pktloc: support to specify a shift operator for packet locations
no users yet though.
This commit is contained in:
parent
d283c8e889
commit
59880cb01e
5 changed files with 56 additions and 21 deletions
44
etc/pktloc
44
etc/pktloc
|
@ -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
|
||||
|
|
|
@ -26,6 +26,7 @@ struct rtnl_pktloc
|
|||
{
|
||||
char * name;
|
||||
uint8_t layer;
|
||||
uint8_t shift;
|
||||
uint16_t offset;
|
||||
uint16_t align;
|
||||
uint32_t mask;
|
||||
|
|
|
@ -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)]);
|
||||
|
||||
|
|
|
@ -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; }
|
||||
;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue