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/nbyte.h>
18#include <linux/tc_ematch/tc_em_nbyte.h>
22 struct tcf_em_nbyte cfg;
26void rtnl_ematch_nbyte_set_offset(
struct rtnl_ematch *e, uint8_t layer,
34uint16_t rtnl_ematch_nbyte_get_offset(
struct rtnl_ematch *e)
36 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.off;
39uint8_t rtnl_ematch_nbyte_get_layer(
struct rtnl_ematch *e)
41 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.layer;
44void rtnl_ematch_nbyte_set_pattern(
struct rtnl_ematch *e,
45 uint8_t *pattern,
size_t len)
56uint8_t *rtnl_ematch_nbyte_get_pattern(
struct rtnl_ematch *e)
58 return ((
struct nbyte_data *) rtnl_ematch_data(e))->pattern;
61size_t rtnl_ematch_nbyte_get_len(
struct rtnl_ematch *e)
63 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.len;
66static const char *layer_txt(
struct tcf_em_nbyte *nbyte)
68 switch (nbyte->layer) {
71 case TCF_LAYER_NETWORK:
73 case TCF_LAYER_TRANSPORT:
80static int nbyte_parse(
struct rtnl_ematch *e,
void *data,
size_t len)
83 size_t hdrlen =
sizeof(
struct tcf_em_nbyte);
84 size_t plen = len - hdrlen;
86 memcpy(&n->cfg, data, hdrlen);
88 if (!(n->pattern = calloc(1, plen)))
91 memcpy(n->pattern, (
char *) data + hdrlen, plen);
97static void nbyte_dump(
struct rtnl_ematch *e,
struct nl_dump_params *p)
102 nl_dump(p,
"pattern(%u:[", n->cfg.len);
104 for (i = 0; i < n->cfg.len; i++) {
105 nl_dump(p,
"%02x", n->pattern[i]);
106 if (i+1 < n->cfg.len)
110 nl_dump(p,
"] at %s+%u)", layer_txt(&n->cfg), n->cfg.off);
113static void nbyte_free(
struct rtnl_ematch *e)
120 .eo_kind = TCF_EM_NBYTE,
122 .eo_minlen =
sizeof(
struct tcf_em_nbyte),
124 .eo_parse = nbyte_parse,
125 .eo_dump = nbyte_dump,
126 .eo_free = nbyte_free,
129static 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.