]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
pktloc: support to specify a shift operator for packet locations
authorThomas GraF <tgraf@suug.ch>
Thu, 4 Nov 2010 19:01:36 +0000 (20:01 +0100)
committerThomas GraF <tgraf@suug.ch>
Thu, 4 Nov 2010 19:01:36 +0000 (20:01 +0100)
no users yet though.

etc/pktloc
include/netlink/route/pktloc.h
lib/route/pktloc.c
lib/route/pktloc_syntax.y
src/nl-pktloc-lookup.c

index 96f5a41246498d2d3642608d2204d73f6afc0672..505c44e606f37a55069563cc1be8a9604fa2f6c5 100644 (file)
@@ -2,14 +2,15 @@
 # Location definitions for packet matching
 #
 
-# name         alignment       offset          mask
-ip.version     u8              net+0           0xF0
+# name         alignment       offset          mask            shift
+ip.version     u8              net+0           0xF0            4
 ip.hdrlen      u8              net+0           0x0F
 ip.diffserv    u8              net+1
 ip.length      u16             net+2
 ip.id          u16             net+4
-ip.df          u8              net+6           0x40
-ip.mf          u8              net+6           0x20
+ip.flag.res    u8              net+6           0xff            7
+ip.df          u8              net+6           0x40            6
+ip.mf          u8              net+6           0x20            5
 ip.offset      u16             net+6           0x1FFF
 ip.ttl         u8              net+8
 ip.proto       u8              net+9
@@ -17,12 +18,16 @@ ip.chksum   u16             net+10
 ip.src         u32             net+12
 ip.dst         u32             net+16
 
+# if ip.ihl > 5
+ip.opts                u32             net+20
+
+
 #
 # IP version 6
 #
-# name         alignment       offset          mask
-ip6.version    u8              net+0           0xF0
-ip6.tc         u16             net+0           0xFF0
+# name         alignment       offset          mask            shift
+ip6.version    u8              net+0           0xF0            4
+ip6.tc         u16             net+0           0xFF0           4
 ip6.flowlabel  u32             net+0           0xFFFFF
 ip6.length     u16             net+4
 ip6.nexthdr    u8              net+6
@@ -33,14 +38,29 @@ ip6.dst             16              net+24
 #
 # Transmission Control Protocol (TCP)
 #
-# name         alignment       offset          mask
+# name         alignment       offset          mask            shift
 tcp.sport      u16             tcp+0
 tcp.dport      u16             tcp+2
 tcp.seq                u32             tcp+4
 tcp.ack                u32             tcp+8
-tcp.off                u8              tcp+12          0xF0
-tcp.reserved   u8              tcp+12          0x0F
-# FLAGS
+
+# Data offset (4 bits)
+tcp.off                u8              tcp+12          0xF0            4
+
+# Reserved [0 0 0] (3 bits)
+tcp.reserved   u8              tcp+12          0x04            1
+
+# ECN [N C E] (3 bits)
+tcp.ecn                u16             tcp+12          0x01C00         6
+
+# Individual TCP flags (0|1) (6 bits in total)
+tcp.flag.urg   u8              tcp+13          0x20            5
+tcp.flag.ack   u8              tcp+13          0x10            4
+tcp.flag.psh   u8              tcp+13          0x08            3
+tcp.flag.rst   u8              tcp+13          0x04            2
+tpc.flag.syn   u8              tcp+13          0x02            1
+tcp.flag.fin   u8              tcp+13          0x01
+
 tcp.win                u16             tcp+14
 tcp.csum       u16             tcp+16
 tcp.urg                u16             tcp+18
@@ -49,7 +69,7 @@ tcp.opts      u32             tcp+20
 #
 # User Datagram Protocol (UDP)
 #
-# name         alignment       offset          mask
+# name         alignment       offset          mask            shift
 udp.sport      u16             tcp+0
 udp.dport      u16             tcp+2
 udp.length     u16             tcp+4
index ad8c66c7102e651931aa6c6648685420d3717837..c3768ce96ddddf1e48f3b0ba202cf94a1c11b5db 100644 (file)
@@ -26,6 +26,7 @@ struct rtnl_pktloc
 {
        char *                  name;
        uint8_t                 layer;
+       uint8_t                 shift;
        uint16_t                offset;
        uint16_t                align;
        uint32_t                mask;
index b5e5b7714ac5d5323073e79a12410d155cb5b90b..823a3c77c7c1b02e384347d7108a3b102c3e45e0 100644 (file)
@@ -222,8 +222,9 @@ int rtnl_pktloc_add(struct rtnl_pktloc *loc)
        }
 
        NL_DBG(2, "New packet location entry \"%s\" align=%u layer=%u "
-                 "offset=%u mask=%#x refnt=%u\n", loc->name, loc->align,
-                 loc->layer, loc->offset, loc->mask, loc->refcnt);
+                 "offset=%u mask=%#x shift=%u refnt=%u\n",
+                 loc->name, loc->align, loc->layer, loc->offset,
+                 loc->mask, loc->shift, loc->refcnt);
 
        nl_list_add_tail(&loc->list, &pktloc_name_ht[pktloc_hash(loc->name)]);
 
index 95cd6f43b653b473e1de10db25dc031e54a88566..4a2ce48d7c377ac40316e49072a1a9cf7861ea46 100644 (file)
@@ -13,6 +13,7 @@
 
 %parse-param {void *scanner}
 %lex-param {void *scanner}
+%expect 1
 
 %union {
        struct rtnl_pktloc *l;
@@ -32,7 +33,7 @@ static void yyerror(YYLTYPE *locp, void *scanner, const char *msg)
 %token <i> ERROR NUMBER LAYER ALIGN
 %token <s> NAME
 
-%type <i> mask layer align
+%type <i> mask layer align shift
 %type <l> location
 
 %destructor { free($$); } NAME
@@ -47,7 +48,7 @@ input:
        ;
 
 location:
-       NAME align layer NUMBER mask
+       NAME align layer NUMBER mask shift
                {
                        struct rtnl_pktloc *loc;
 
@@ -62,6 +63,7 @@ location:
                        loc->layer = $3;
                        loc->offset = $4;
                        loc->mask = $5;
+                       loc->shift = $6;
 
                        if (rtnl_pktloc_add(loc) < 0) {
                                NL_DBG(1, "Duplicate packet location entry "
@@ -92,3 +94,10 @@ mask:
        | NUMBER
                { $$ = $1; }
        ;
+
+shift:
+       /* empty */
+               { $$ = 0; }
+       | NUMBER
+               { $$ = $1; }
+       ;
index 0f9831ad1b9dfc4a984f40ffb0aee25618c2790c..17c867b545c75684061fa657dcc3d9a90a864b6e 100644 (file)
@@ -59,6 +59,9 @@ static void dump_u32_style(struct rtnl_pktloc *loc, uint32_t value)
                nl_cli_fatal(EINVAL, "u32 does not support link "
                                "layer locations.");
 
+       if (loc->shift > 0)
+               nl_cli_fatal(EINVAL, "u32 does not support shifting.");
+
        printf("%s %x %x at %s%u\n",
                align_txt[loc->align],
                value, loc->mask ? loc->mask : align_mask[loc->align],
@@ -80,21 +83,22 @@ static char *get_align_txt(struct rtnl_pktloc *loc)
 
 static void dump_loc(struct rtnl_pktloc *loc)
 {
-       printf("%s = %s at %s+%u %#x\n",
+       printf("%s = %s at %s+%u & %#x >> %u\n",
                loc->name, get_align_txt(loc), layer_txt[loc->layer],
-               loc->offset, loc->mask);
+               loc->offset, loc->mask, loc->shift);
 }
 
 static void list_cb(struct rtnl_pktloc *loc, void *arg)
 {
-       printf("%-26s %-5s %3s+%-4u %#-10x %u\n",
+       printf("%-26s %-5s %3s+%-4u %#-10x %-8u %u\n",
                loc->name, get_align_txt(loc), layer_txt[loc->layer],
-               loc->offset, loc->mask, loc->refcnt);
+               loc->offset, loc->mask, loc->shift, loc->refcnt);
 }
 
 static void do_list(void)
 {
-       printf("name                      align  offset  mask     refcnt\n");
+       printf(
+"name                      align  offset  mask     shift    refcnt\n");
        printf("---------------------------------------------------------\n");
 
        rtnl_pktloc_foreach(&list_cb, NULL);