19 #include <netlink-private/netlink.h>
20 #include <netlink-private/tc.h>
21 #include <netlink/netlink.h>
22 #include <netlink/route/cls/ematch.h>
23 #include <netlink/route/cls/ematch/nbyte.h>
27 struct tcf_em_nbyte cfg;
31 void rtnl_ematch_nbyte_set_offset(
struct rtnl_ematch *e, uint8_t layer,
39 uint16_t rtnl_ematch_nbyte_get_offset(
struct rtnl_ematch *e)
41 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.off;
44 uint8_t rtnl_ematch_nbyte_get_layer(
struct rtnl_ematch *e)
46 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.layer;
49 void rtnl_ematch_nbyte_set_pattern(
struct rtnl_ematch *e,
50 uint8_t *pattern,
size_t len)
61 uint8_t *rtnl_ematch_nbyte_get_pattern(
struct rtnl_ematch *e)
63 return ((
struct nbyte_data *) rtnl_ematch_data(e))->pattern;
66 size_t rtnl_ematch_nbyte_get_len(
struct rtnl_ematch *e)
68 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.len;
71 static const char *layer_txt(
struct tcf_em_nbyte *nbyte)
73 switch (nbyte->layer) {
76 case TCF_LAYER_NETWORK:
78 case TCF_LAYER_TRANSPORT:
85 static int nbyte_parse(
struct rtnl_ematch *e,
void *data,
size_t len)
88 size_t hdrlen =
sizeof(
struct tcf_em_nbyte);
89 size_t plen = len - hdrlen;
91 memcpy(&n->cfg, data, hdrlen);
93 if (!(n->pattern = calloc(1, plen)))
96 memcpy(n->pattern, data + hdrlen, plen);
102 static void nbyte_dump(
struct rtnl_ematch *e,
struct nl_dump_params *p)
107 nl_dump(p,
"pattern(%u:[", n->cfg.len);
109 for (i = 0; i < n->cfg.len; i++) {
110 nl_dump(p,
"%02x", n->pattern[i]);
111 if (i+1 < n->cfg.len)
115 nl_dump(p,
"] at %s+%u)", layer_txt(&n->cfg), n->cfg.off);
118 static void nbyte_free(
struct rtnl_ematch *e)
125 .eo_kind = TCF_EM_NBYTE,
127 .eo_minlen =
sizeof(
struct tcf_em_nbyte),
129 .eo_parse = nbyte_parse,
130 .eo_dump = nbyte_dump,
131 .eo_free = nbyte_free,
134 static void __init nbyte_init(
void)