1 /* 2 * lib/route/cls/ematch_grammar.l ematch expression grammar 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation version 2.1 7 * of the License. 8 * 9 * Copyright (c) 2010-2013 Thomas Graf <tgraf@suug.ch> 10 */ 11 12 %{ 13 #include <netlink-private/netlink.h> 14 #include <netlink-private/tc.h> 15 #include <netlink/netlink.h> 16 #include <netlink/route/cls/ematch.h> 17 #include <netlink/route/cls/ematch/cmp.h> 18 #include <linux/tc_ematch/tc_em_cmp.h> 19 #include "ematch_syntax.h" 20 21 int ematch_get_column(yyscan_t); 22 void ematch_set_column(int, yyscan_t); 23 %} 24 25 %option 8bit 26 %option reentrant 27 %option warn 28 %option noyywrap 29 %option noinput 30 %option nounput 31 %option bison-bridge 32 %option prefix="ematch_" 33 34 %x QUOTE 35 36 %% 37 38 [ \t\r\n]+ 39 40 \" { 41 NL_DBG(4, "Beginning of quote\n"); 42 yylval->q.len = 32; 43 if (!(yylval->q.data = calloc(1, yylval->q.len))) 44 return ERROR; 45 46 yylval->q.index = 0; 47 BEGIN(QUOTE); 48 } 49 50 <QUOTE>[^\\\n\"]+ { 51 memcpy(yylval->q.data + yylval->q.index, yytext, 52 strlen(yytext)); 53 yylval->q.index += strlen(yytext); 54 } 55 56 <QUOTE>\" { 57 BEGIN(0); 58 return QUOTED; 59 } 60 61 62 [[:digit:]]+ | 63 0[xX][[:xdigit:]]+ { 64 yylval->i = strtoul(yytext, NULL, 0); 65 return NUMBER; 66 } 67 68 eq | 69 "=" return KW_EQ; 70 gt | 71 ">" return KW_GT; 72 lt | 73 "<" return KW_LT; 74 75 [aA][nN][dD] | 76 "&&" { yylval->i = TCF_EM_REL_AND; return LOGIC; } 77 [oO][rR] | 78 "||" { yylval->i = TCF_EM_REL_OR; return LOGIC; } 79 [nN][oO][tT] | 80 "!" return NOT; 81 82 [cC][mM][pP] { yylval->i = TCF_EM_CMP; return EMATCH_CMP; } 83 [pP][aA][tT][tT][eE][rR][nN] { yylval->i = TCF_EM_NBYTE; return EMATCH_NBYTE; } 84 [tT][eE][xX][tT] { yylval->i = TCF_EM_TEXT; return EMATCH_TEXT; } 85 [mM][eE][tT][aA] { yylval->i = TCF_EM_META; return EMATCH_META; } 86 87 "(" return KW_OPEN; 88 ")" return KW_CLOSE; 89 [mM][aA][sS][kK] | 90 "&" return KW_MASK; 91 [sS][hH][iI][fF][tT] | 92 ">>" return KW_SHIFT; 93 [aA][tT] return KW_AT; 94 "+" return KW_PLUS; 95 [fF][rR][oO][mM] return KW_FROM; 96 [tT][oO] return KW_TO; 97 98 [uU]8 { yylval->i = TCF_EM_ALIGN_U8; return ALIGN; } 99 [uU]16 { yylval->i = TCF_EM_ALIGN_U16; return ALIGN; } 100 [uU]32 { yylval->i = TCF_EM_ALIGN_U32; return ALIGN; } 101 102 [lL][iI][nN][kK] | 103 [eE][tT][hH] { yylval->i = TCF_LAYER_LINK; return LAYER; } 104 [nN][eE][tT] | 105 [iI][pP]6 | 106 [iI][pP] { yylval->i = TCF_LAYER_NETWORK; return LAYER; } 107 [tT][rR][aA][nN][sS][pP][oO][rR][tT] | 108 [tT][cC][pP] { yylval->i = TCF_LAYER_TRANSPORT; return LAYER; } 109 110 random return META_RANDOM; 111 loadavg_0 return META_LOADAVG_0; 112 loadavg_1 return META_LOADAVG_1; 113 loadavg_2 return META_LOADAVG_2; 114 dev return META_DEV; 115 prio return META_PRIO; 116 proto return META_PROTO; 117 pkttype return META_PKTTYPE; 118 pktlen return META_PKTLEN; 119 datalen return META_DATALEN; 120 maclen return META_MACLEN; 121 mark return META_MARK; 122 tcindex return META_TCINDEX; 123 rtclassid return META_RTCLASSID; 124 rtiif return META_RTIIF; 125 sk_family return META_SK_FAMILY; 126 sk_state return META_SK_STATE; 127 sk_reuse return META_SK_REUSE; 128 sk_refcnt return META_SK_REFCNT; 129 sk_rcvbuf return META_SK_RCVBUF; 130 sk_sndbuf return META_SK_SNDBUF; 131 sk_shutdown return META_SK_SHUTDOWN; 132 sk_proto return META_SK_PROTO; 133 sk_type return META_SK_TYPE; 134 sk_rmem_alloc return META_SK_RMEM_ALLOC; 135 sk_wmem_alloc return META_SK_WMEM_ALLOC; 136 sk_wmem_queued return META_SK_WMEM_QUEUED; 137 sk_rcv_qlen return META_SK_RCV_QLEN; 138 sk_snd_qlen return META_SK_SND_QLEN; 139 sk_err_qlen return META_SK_ERR_QLEN; 140 sk_forward_allocs return META_SK_FORWARD_ALLOCS; 141 sk_allocs return META_SK_ALLOCS; 142 sk_route_caps return META_SK_ROUTE_CAPS; 143 sk_hash return META_SK_HASH; 144 sk_lingertime return META_SK_LINGERTIME; 145 sk_ack_backlog return META_SK_ACK_BACKLOG; 146 sk_max_ack_backlog return META_SK_MAX_ACK_BACKLOG; 147 sk_prio return META_SK_PRIO; 148 sk_rcvlowat return META_SK_RCVLOWAT; 149 sk_rcvtimeo return META_SK_RCVTIMEO; 150 sk_sndtimeo return META_SK_SNDTIMEO; 151 sk_sendmsg_off return META_SK_SENDMSG_OFF; 152 sk_write_pending return META_SK_WRITE_PENDING; 153 vlan return META_VLAN; 154 rxhash return META_RXHASH; 155 156 devname return META_DEVNAME; 157 sk_bound_if return META_SK_BOUND_IF; 158 159 160 [^ \t\r\n+()=<>&|\"]+ { 161 yylval->s = strdup(yytext); 162 if (yylval->s == NULL) 163 return ERROR; 164 NL_DBG(4, "lex STR=%s\n", yylval->s); 165 return STR; 166 } 167