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> 24 #include <linux/tc_ematch/tc_em_nbyte.h> 28 struct tcf_em_nbyte cfg;
32 void rtnl_ematch_nbyte_set_offset(
struct rtnl_ematch *e, uint8_t layer,
40 uint16_t rtnl_ematch_nbyte_get_offset(
struct rtnl_ematch *e)
42 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.off;
45 uint8_t rtnl_ematch_nbyte_get_layer(
struct rtnl_ematch *e)
47 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.layer;
50 void rtnl_ematch_nbyte_set_pattern(
struct rtnl_ematch *e,
51 uint8_t *pattern,
size_t len)
62 uint8_t *rtnl_ematch_nbyte_get_pattern(
struct rtnl_ematch *e)
64 return ((
struct nbyte_data *) rtnl_ematch_data(e))->pattern;
67 size_t rtnl_ematch_nbyte_get_len(
struct rtnl_ematch *e)
69 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.len;
72 static const char *layer_txt(
struct tcf_em_nbyte *nbyte)
74 switch (nbyte->layer) {
77 case TCF_LAYER_NETWORK:
79 case TCF_LAYER_TRANSPORT:
86 static int nbyte_parse(
struct rtnl_ematch *e,
void *data,
size_t len)
89 size_t hdrlen =
sizeof(
struct tcf_em_nbyte);
90 size_t plen = len - hdrlen;
92 memcpy(&n->cfg, data, hdrlen);
94 if (!(n->pattern = calloc(1, plen)))
97 memcpy(n->pattern, data + hdrlen, plen);
103 static void nbyte_dump(
struct rtnl_ematch *e,
struct nl_dump_params *p)
108 nl_dump(p,
"pattern(%u:[", n->cfg.len);
110 for (i = 0; i < n->cfg.len; i++) {
111 nl_dump(p,
"%02x", n->pattern[i]);
112 if (i+1 < n->cfg.len)
116 nl_dump(p,
"] at %s+%u)", layer_txt(&n->cfg), n->cfg.off);
119 static void nbyte_free(
struct rtnl_ematch *e)
126 .eo_kind = TCF_EM_NBYTE,
128 .eo_minlen =
sizeof(
struct tcf_em_nbyte),
130 .eo_parse = nbyte_parse,
131 .eo_dump = nbyte_dump,
132 .eo_free = nbyte_free,
135 static void __init nbyte_init(
void)
int rtnl_ematch_register(struct rtnl_ematch_ops *ops)
Register ematch module.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Extended Match Operations.