diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-10-28 22:20:42 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-28 22:20:42 (GMT) |
commit | d7a561a1372f819efc8cede30dc550d8e3afcc28 (patch) | |
tree | da9fefa62f5ffdca82fa374ebe0b207202719410 /include | |
parent | e1eacd6b16b014eb42bcf6683ebe2334c3a35c68 (diff) | |
download | libnl-d7a561a1372f819efc8cede30dc550d8e3afcc28.zip libnl-d7a561a1372f819efc8cede30dc550d8e3afcc28.tar.gz libnl-d7a561a1372f819efc8cede30dc550d8e3afcc28.tar.bz2 |
Tons of ematch work
- Fixes a bunch of bugs related to ematches
- Adds support for the nbyte ematch
- Adds a bison/flex parser for ematch expressions, expressions
may look like this:
ip.length > 256 && pattern(ip6.src = 3ffe::/16)
documenation on syntax follows
- adds ematch support to the basic classifier (--ematch EXPR)
Diffstat (limited to 'include')
-rw-r--r-- | include/netlink-types.h | 10 | ||||
-rw-r--r-- | include/netlink/cli/cls.h | 1 | ||||
-rw-r--r-- | include/netlink/route/cls/basic.h | 14 | ||||
-rw-r--r-- | include/netlink/route/cls/ematch.h | 96 | ||||
-rw-r--r-- | include/netlink/route/cls/ematch/cmp.h | 3 | ||||
-rw-r--r-- | include/netlink/route/cls/ematch/nbyte.h | 36 |
6 files changed, 111 insertions, 49 deletions
diff --git a/include/netlink-types.h b/include/netlink-types.h index 3abeff4..3dc760f 100644 --- a/include/netlink-types.h +++ b/include/netlink-types.h @@ -520,12 +520,14 @@ struct rtnl_ematch uint16_t e_id; uint16_t e_kind; uint16_t e_flags; + uint16_t e_index; + size_t e_datalen; struct nl_list_head e_childs; struct nl_list_head e_list; struct rtnl_ematch_ops *e_ops; - char e_data[0]; + void * e_data; }; struct rtnl_ematch_tree @@ -834,4 +836,10 @@ struct nfnl_queue_msg { uint32_t queue_msg_verdict; }; +struct ematch_quoted { + char * data; + size_t len; + int index; +}; + #endif diff --git a/include/netlink/cli/cls.h b/include/netlink/cli/cls.h index 85e5ffe..cdcb17e 100644 --- a/include/netlink/cli/cls.h +++ b/include/netlink/cli/cls.h @@ -29,6 +29,7 @@ extern struct nl_cache * nl_cli_cls_alloc_cache(struct nl_sock *, int, uint32_t); extern void nl_cli_cls_parse_kind(struct rtnl_cls *, char *); extern void nl_cli_cls_parse_proto(struct rtnl_cls *, char *); +extern struct rtnl_ematch_tree *nl_cli_cls_parse_ematch(struct rtnl_cls *, char *); extern struct nl_cli_cls_module *nl_cli_cls_lookup(struct rtnl_cls_ops *); extern void nl_cli_cls_register(struct nl_cli_cls_module *); diff --git a/include/netlink/route/cls/basic.h b/include/netlink/route/cls/basic.h index 7003124..8b58c1e 100644 --- a/include/netlink/route/cls/basic.h +++ b/include/netlink/route/cls/basic.h @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2008-2010 Thomas Graf <tgraf@suug.ch> */ #ifndef NETLINK_BASIC_H_ @@ -18,13 +18,11 @@ extern "C" { #endif -extern struct rtnl_cls_ops *rtnl_basic_get_ops(void); -extern int rtnl_basic_set_classid(struct rtnl_cls *, uint32_t); -extern uint32_t rtnl_basic_get_classid(struct rtnl_cls *); -extern int rtnl_basic_set_ematch(struct rtnl_cls *, - struct rtnl_ematch_tree *); -extern struct rtnl_ematch_tree * - rtnl_basic_get_ematch(struct rtnl_cls *); +extern void rtnl_basic_set_target(struct rtnl_cls *, uint32_t); +extern uint32_t rtnl_basic_get_target(struct rtnl_cls *); +extern void rtnl_basic_set_ematch(struct rtnl_cls *, + struct rtnl_ematch_tree *); +extern struct rtnl_ematch_tree *rtnl_basic_get_ematch(struct rtnl_cls *); #ifdef __cplusplus } diff --git a/include/netlink/route/cls/ematch.h b/include/netlink/route/cls/ematch.h index c4292bf..6cf5960 100644 --- a/include/netlink/route/cls/ematch.h +++ b/include/netlink/route/cls/ematch.h @@ -6,13 +6,14 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2008-2010 Thomas Graf <tgraf@suug.ch> */ #ifndef NETLINK_CLS_EMATCH_H_ #define NETLINK_CLS_EMATCH_H_ #include <netlink/netlink.h> +#include <netlink/msg.h> #include <netlink/route/classifier.h> #include <linux/pkt_cls.h> @@ -20,51 +21,68 @@ extern "C" { #endif +/* FIXME: Should be moved to the kernel header at some point */ +#define RTNL_EMATCH_PROGID 2 + struct rtnl_ematch; struct rtnl_ematch_tree; +/** + * Extended Match Operations + */ struct rtnl_ematch_ops { - int eo_kind; - const char * eo_name; - size_t eo_datalen; - - int (*eo_parse)(struct rtnl_ematch *, - void *, size_t); - void (*eo_dump)(struct rtnl_ematch *, - struct nl_dump_params *); - struct nl_list_head eo_list; + int eo_kind; + const char * eo_name; + size_t eo_minlen; + size_t eo_datalen; + + int (*eo_parse)(struct rtnl_ematch *, void *, size_t); + void (*eo_dump)(struct rtnl_ematch *, + struct nl_dump_params *); + int (*eo_fill)(struct rtnl_ematch *, struct nl_msg *); + void (*eo_free)(struct rtnl_ematch *); + struct nl_list_head eo_list; }; -extern int rtnl_ematch_register(struct rtnl_ematch_ops *); -extern int rtnl_ematch_unregister(struct rtnl_ematch_ops *); - -extern struct rtnl_ematch_ops * - rtnl_ematch_lookup_ops(int); -extern struct rtnl_ematch_ops * - rtnl_ematch_lookup_ops_name(const char *); - -extern struct rtnl_ematch * - rtnl_ematch_alloc(struct rtnl_ematch_ops *); -extern void rtnl_ematch_add_child(struct rtnl_ematch *, - struct rtnl_ematch *); -extern void rtnl_ematch_unlink(struct rtnl_ematch *); -extern void rtnl_ematch_free(struct rtnl_ematch *); - -extern void * rtnl_ematch_data(struct rtnl_ematch *); -extern void rtnl_ematch_set_flags(struct rtnl_ematch *, uint16_t); -extern void rtnl_ematch_unset_flags(struct rtnl_ematch *, uint16_t); -extern uint16_t rtnl_ematch_get_flags(struct rtnl_ematch *); - -extern struct rtnl_ematch_tree * - rtnl_ematch_tree_alloc(uint16_t); -extern void rtnl_ematch_tree_free(struct rtnl_ematch_tree *); - -extern int rtnl_ematch_parse(struct nlattr *, struct rtnl_ematch_tree **); -extern void rtnl_ematch_tree_add_tail(struct rtnl_ematch_tree *, - struct rtnl_ematch *); -extern void rtnl_ematch_tree_dump(struct rtnl_ematch_tree *, - struct nl_dump_params *); +extern int rtnl_ematch_register(struct rtnl_ematch_ops *); +extern struct rtnl_ematch_ops * rtnl_ematch_lookup_ops(int); +extern struct rtnl_ematch_ops * rtnl_ematch_lookup_ops_by_name(const char *); + +extern struct rtnl_ematch * rtnl_ematch_alloc(void); +extern int rtnl_ematch_add_child(struct rtnl_ematch *, + struct rtnl_ematch *); +extern void rtnl_ematch_unlink(struct rtnl_ematch *); +extern void rtnl_ematch_free(struct rtnl_ematch *); + +extern void * rtnl_ematch_data(struct rtnl_ematch *); +extern void rtnl_ematch_set_flags(struct rtnl_ematch *, + uint16_t); +extern void rtnl_ematch_unset_flags(struct rtnl_ematch *, + uint16_t); +extern uint16_t rtnl_ematch_get_flags(struct rtnl_ematch *); +extern int rtnl_ematch_set_ops(struct rtnl_ematch *, + struct rtnl_ematch_ops *); +extern int rtnl_ematch_set_kind(struct rtnl_ematch *, + uint16_t); +extern int rtnl_ematch_set_name(struct rtnl_ematch *, + const char *); + +extern struct rtnl_ematch_tree *rtnl_ematch_tree_alloc(uint16_t); +extern void rtnl_ematch_tree_free(struct rtnl_ematch_tree *); +extern void rtnl_ematch_tree_add(struct rtnl_ematch_tree *, + struct rtnl_ematch *); + +extern int rtnl_ematch_parse_attr(struct nlattr *, + struct rtnl_ematch_tree **); +extern int rtnl_ematch_fill_attr(struct nl_msg *, int, + struct rtnl_ematch_tree *); +extern void rtnl_ematch_tree_dump(struct rtnl_ematch_tree *, + struct nl_dump_params *); + + +extern int rtnl_ematch_parse_expr(const char *, char **, + struct rtnl_ematch_tree **); #ifdef __cplusplus } diff --git a/include/netlink/route/cls/ematch/cmp.h b/include/netlink/route/cls/ematch/cmp.h index b4ad03a..308113e 100644 --- a/include/netlink/route/cls/ematch/cmp.h +++ b/include/netlink/route/cls/ematch/cmp.h @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2008-2010 Thomas Graf <tgraf@suug.ch> */ #ifndef NETLINK_CLS_EMATCH_CMP_H_ @@ -14,6 +14,7 @@ #include <netlink/netlink.h> #include <netlink/route/cls/ematch.h> +#include <linux/tc_ematch/tc_em_cmp.h> #ifdef __cplusplus extern "C" { diff --git a/include/netlink/route/cls/ematch/nbyte.h b/include/netlink/route/cls/ematch/nbyte.h new file mode 100644 index 0000000..014c719 --- /dev/null +++ b/include/netlink/route/cls/ematch/nbyte.h @@ -0,0 +1,36 @@ +/* + * netlink/route/cls/ematch/nbyte.h N-Byte Comparison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch> + */ + +#ifndef NETLINK_CLS_EMATCH_NBYTE_H_ +#define NETLINK_CLS_EMATCH_NBYTE_H_ + +#include <netlink/netlink.h> +#include <netlink/route/cls/ematch.h> +#include <linux/tc_ematch/tc_em_nbyte.h> + +#ifdef __cplusplus +extern "C" { +#endif + +extern void rtnl_ematch_nbyte_set_offset(struct rtnl_ematch *, + uint8_t, uint16_t); +extern uint16_t rtnl_ematch_nbyte_get_offset(struct rtnl_ematch *); +extern uint8_t rtnl_ematch_nbyte_get_layer(struct rtnl_ematch *); +extern void rtnl_ematch_nbyte_set_pattern(struct rtnl_ematch *, + uint8_t *, size_t); +extern uint8_t * rtnl_ematch_nbyte_get_pattern(struct rtnl_ematch *); +extern size_t rtnl_ematch_nbyte_get_len(struct rtnl_ematch *); + +#ifdef __cplusplus +} +#endif + +#endif |