2 * lib/route/cls/ematch/cmp.c Simple packet data comparison ematch
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
14 * @defgroup em_cmp Simple packet data comparison
19 #include <netlink-local.h>
20 #include <netlink-tc.h>
21 #include <netlink/netlink.h>
22 #include <netlink/route/cls/ematch.h>
23 #include <linux/tc_ematch/tc_em_cmp.h>
25 void rtnl_ematch_cmp_set(struct rtnl_ematch *ematch,
26 struct tcf_em_cmp *cfg)
28 memcpy(rtnl_ematch_data(ematch), cfg, sizeof(*cfg));
31 struct tcf_em_cmp *rtnl_ematch_cmp_get(struct rtnl_ematch *ematch)
33 return rtnl_ematch_data(ematch);
36 static const char *align_txt(struct tcf_em_cmp *cmp)
41 case TCF_EM_ALIGN_U16:
42 return (cmp->flags & TCF_EM_CMP_TRANS) ? "h16" : "u16";
43 case TCF_EM_ALIGN_U32:
44 return (cmp->flags & TCF_EM_CMP_TRANS) ? "h32" : "u32";
46 return (cmp->flags & TCF_EM_CMP_TRANS) ? "h?" : "u?";
50 static const char *layer_txt(struct tcf_em_cmp *cmp)
55 case TCF_LAYER_NETWORK:
57 case TCF_LAYER_TRANSPORT:
64 static const char *relation_txt(struct tcf_em_cmp *cmp)
78 static int cmp_parse(struct rtnl_ematch *m, void *data, size_t len)
80 memcpy(rtnl_ematch_data(m), data, len);
85 static void cmp_dump(struct rtnl_ematch *m, struct nl_dump_params *p)
87 struct tcf_em_cmp *cmp = rtnl_ematch_data(m);
89 nl_dump(p, "%s at %s+%u ",
90 align_txt(cmp), layer_txt(cmp), cmp->off);
93 nl_dump(p, "& 0x%x ", cmp->mask);
95 nl_dump(p, "%s %u", relation_txt(cmp), cmp->val);
98 static struct rtnl_ematch_ops cmp_ops = {
99 .eo_kind = TCF_EM_CMP,
101 .eo_datalen = sizeof(struct tcf_em_cmp),
102 .eo_parse = cmp_parse,
106 static void __init cmp_init(void)
108 rtnl_ematch_register(&cmp_ops);
111 static void __exit cmp_exit(void)
113 rtnl_ematch_unregister(&cmp_ops);