13#include "nl-default.h"
15#include <linux/tc_ematch/tc_em_nbyte.h>
17#include <netlink/netlink.h>
18#include <netlink/route/cls/ematch.h>
19#include <netlink/route/cls/ematch/nbyte.h>
23 struct tcf_em_nbyte cfg;
27void rtnl_ematch_nbyte_set_offset(
struct rtnl_ematch *e, uint8_t layer,
35uint16_t rtnl_ematch_nbyte_get_offset(
struct rtnl_ematch *e)
37 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.off;
40uint8_t rtnl_ematch_nbyte_get_layer(
struct rtnl_ematch *e)
42 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.layer;
45void rtnl_ematch_nbyte_set_pattern(
struct rtnl_ematch *e,
46 uint8_t *pattern,
size_t len)
57uint8_t *rtnl_ematch_nbyte_get_pattern(
struct rtnl_ematch *e)
59 return ((
struct nbyte_data *) rtnl_ematch_data(e))->pattern;
62size_t rtnl_ematch_nbyte_get_len(
struct rtnl_ematch *e)
64 return ((
struct nbyte_data *) rtnl_ematch_data(e))->cfg.len;
67static const char *layer_txt(
struct tcf_em_nbyte *nbyte)
69 switch (nbyte->layer) {
72 case TCF_LAYER_NETWORK:
74 case TCF_LAYER_TRANSPORT:
81static int nbyte_parse(
struct rtnl_ematch *e,
void *data,
size_t len)
84 size_t hdrlen =
sizeof(
struct tcf_em_nbyte);
85 size_t plen = len - hdrlen;
87 memcpy(&n->cfg, data, hdrlen);
89 if (!(n->pattern = calloc(1, plen)))
92 memcpy(n->pattern, (
char *) data + hdrlen, plen);
98static void nbyte_dump(
struct rtnl_ematch *e,
struct nl_dump_params *p)
103 nl_dump(p,
"pattern(%u:[", n->cfg.len);
105 for (i = 0; i < n->cfg.len; i++) {
106 nl_dump(p,
"%02x", n->pattern[i]);
107 if (i+1 < n->cfg.len)
111 nl_dump(p,
"] at %s+%u)", layer_txt(&n->cfg), n->cfg.off);
114static void nbyte_free(
struct rtnl_ematch *e)
121 .eo_kind = TCF_EM_NBYTE,
123 .eo_minlen =
sizeof(
struct tcf_em_nbyte),
125 .eo_parse = nbyte_parse,
126 .eo_dump = nbyte_dump,
127 .eo_free = nbyte_free,
130static void _nl_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.