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