xtables-eb for the compatibility layer
Subsystems (2)
cover xtables-eb for the compatibility layer
Hi,
this patchset implements ebtables for the nftables compatibility layer. I would explain some points:
- The code is not built with the gcc version 4.7.3 (Gentoo 4.7.3-r1 p1.3, pie-0.5.5):
xtables_multi-nft-bridge.o:/home/giuseppe/git/iptables-nftables/iptables/nft-bridge.c:53: first defined here xtables_multi-nft-bridge.o: In function `nft_rule_to_xtables_ebt_entry':/home/giuseppe/git/iptables-nftables/iptables/nft-bridge.c:226: multiple definition of `nft_rule_to_xtables_ebt_entry' xtables_multi-nft-bridge.o:/home/giuseppe/git/iptables-nftables/iptables/nft-bridge.c:226: first defined here xtables_multi-nft-bridge.o:(.data+0x0): multiple definition of `nft_family_ops_bridge' xtables_multi-nft-bridge.o:(.data+0x0): first defined here
collect2: error: ld returned 1 exit status
but, with the gcc version 4.8.2 (Debian 4.8.2-1) (on my vm) it works fine. I didn't figure out the reason, honestly.
- I didn't figure out how to replace some parts of codes, for istance:
from xtables-eb.c, line 928:
t = (struct ebt_u_target *)new_entry->t;
if ((t->parse(c - t->option_offset, argv, argc, new_entry, &t->flags, &t->t))) {
if (ebt_errormsg[0] != '\0')
return -1;
goto check_extension;}
/* Is it a match_option? */
for (m = ebt_matches; m; m = m->next)
if (m->parse(c - m->option_offset, argv, argc, new_entry, &m->flags, &m->m)) break;
if (m != NULL) {
if (ebt_errormsg[0] != '\0')
return -1;
if (m->used == 0) {
ebt_add_match(new_entry, m);
m->used = 1;
}
goto check_extension;}
Looking at extensions, I noticed that any xtables_match/xtables_target have parse functions. Maybe I'm wrong. Even the code from line 992 is not very clear, about final checks. I don't know if I can remove this part of code.
Thanks
Giuseppe Longo (2):
xtables: bootstrap xtables-eb for nftables
Operations for bridge family
include/linux/netfilter_bridge.h | 33 + include/linux/netfilter_bridge/ebtables.h | 276 +++++++ include/linux/netfilter_bridge/ethernetdb.h | 58 ++ iptables/Makefile.am | 8 +- iptables/getethertype.c | 161 ++++ iptables/nft-bridge.c | 384 +++++++++ iptables/nft-shared.c | 3 + iptables/nft.c | 28 + iptables/nft.h | 12 + iptables/xtables-eb-standalone.c | 87 +++ iptables/xtables-eb.c | 1122 +++++++++++++++++++++++++++ iptables/xtables-ebtables.h | 39 + iptables/xtables-multi.c | 1 + iptables/xtables-multi.h | 1 + 14 files changed, 2210 insertions(+), 3 deletions(-) create mode 100644 include/linux/netfilter_bridge.h create mode 100644 include/linux/netfilter_bridge/ebtables.h create mode 100644 include/linux/netfilter_bridge/ethernetdb.h create mode 100644 iptables/getethertype.c create mode 100644 iptables/nft-bridge.c create mode 100644 iptables/xtables-eb-standalone.c create mode 100644 iptables/xtables-eb.c create mode 100644 iptables/xtables-ebtables.h
Signature · 1 line
1.8.1.5
PATCH 1/2 xtables: bootstrap xtables-eb for nftables
This patch bootstraps xtables-eb for the nftables compatibility layer
--- include/linux/netfilter_bridge.h | 33 + include/linux/netfilter_bridge/ebtables.h | 276 +++++++ include/linux/netfilter_bridge/ethernetdb.h | 58 ++ iptables/Makefile.am | 6 +- iptables/getethertype.c | 161 ++++ iptables/nft.c | 28 + iptables/nft.h | 9 + iptables/xtables-eb-standalone.c | 87 +++ iptables/xtables-eb.c | 1122 +++++++++++++++++++++++++++ iptables/xtables-ebtables.h | 39 + iptables/xtables-multi.c | 1 + iptables/xtables-multi.h | 1 + 12 files changed, 1819 insertions(+), 2 deletions(-) create mode 100644 include/linux/netfilter_bridge.h create mode 100644 include/linux/netfilter_bridge/ebtables.h create mode 100644 include/linux/netfilter_bridge/ethernetdb.h create mode 100644 iptables/getethertype.c create mode 100644 iptables/xtables-eb-standalone.c create mode 100644 iptables/xtables-eb.c create mode 100644 iptables/xtables-ebtables.h
include/linux/netfilter_bridge.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef __LINUX_BRIDGE_NETFILTER_H +#define __LINUX_BRIDGE_NETFILTER_H + +/* bridge-specific defines for netfilter. +*/ +#include <limits.h> + +/* Bridge Hooks */ +/* After promisc drops, checksum checks. */ +#define NF_BR_PRE_ROUTING 0 +/* If the packet is destined for this box. */ +#define NF_BR_LOCAL_IN 1 +/* If the packet is destined for another interface. */ +#define NF_BR_FORWARD 2 +/* Packets coming from a local process. */ +#define NF_BR_LOCAL_OUT 3 +/* Packets about to hit the wire. */ +#define NF_BR_POST_ROUTING 4 +/* Not really a hook, but used for the ebtables broute table */ +#define NF_BR_BROUTING 5 +#define NF_BR_NUMHOOKS 6 + +enum nf_br_hook_priorities { +NF_BR_PRI_FIRST =INT_MIN , +NF_BR_PRI_FILTER_BRIDGED =-200 , +NF_BR_PRI_FILTER_OTHER =200 , +NF_BR_PRI_NAT_DST_BRIDGED =-300 , +NF_BR_PRI_NAT_DST_OTHER =100 , +NF_BR_PRI_NAT_SRC =300 , +NF_BR_PRI_LAST =INT_MAX , +}; + +#endif
include/linux/netfilter_bridge/ebtables.h new file +276 -0
276 lines not on this page · raw message
include/linux/netfilter_bridge/ethernetdb.h new file +58 -0
58 lines not on this page · raw message
iptables/Makefile.am +4 -2
@@ -32,7 +32,9 @@ xtables_multi_SOURCES += xtables-save.c xtables-restore.c \ xtables-standalone.c xtables.c nft.c \ nft-shared.c nft-ipv4.c nft-ipv6.c nft-arp.c \ xtables-config.c xtables-events.c \ - xtables-arp-standalone.c xtables-arp.c + xtables-arp-standalone.c xtables-arp.c \ + getethertype.c nft-bridge.c \ + xtables-eb-standalone.c xtables-eb.c xtables_multi_LDADD += -lmnl -lnftables ${libmnl_LIBS} ${libnftables_LIBS} xtables_multi_CFLAGS += -DENABLE_NFTABLES # yacc and lex generate dirty code
@@ -57,7 +59,7 @@ v6_sbin_links = ip6tables ip6tables-restore ip6tables-save endif if ENABLE_NFTABLES x_sbin_links = xtables xtables-restore xtables-save xtables-config \ - xtables-events xtables-arp + xtables-events xtables-arp xtables-eb endif iptables-extensions.8: ${srcdir}/iptables-extensions.8.tmpl ../extensions/matches.man ../extensions/targets.man
iptables/getethertype.c new file +161 -0
161 lines not on this page · raw message
iptables/nft.c +28 -0
@@ -427,6 +427,34 @@ struct builtin_table xtables_arp[TABLES_MAX] = { }, }; +#include <linux/netfilter_bridge.h> + +struct builtin_table xtables_bridge[TABLES_MAX ] = { + [FILTER ] = { + .name ="filter" , + .chains = { + { + .name ="INPUT" , + .type ="filter" , + .prio =NF_BR_PRI_FILTER_BRIDGED , + .hook =NF_BR_LOCAL_IN , + }, + { + .name ="FORWARD" , + .type ="filter" , + .prio =NF_BR_PRI_FILTER_BRIDGED , + .hook =NF_BR_FORWARD , + }, + { + .name ="OUTPUT" , + .type ="filter" , + .prio =NF_BR_PRI_FILTER_BRIDGED , + .hook =NF_BR_LOCAL_OUT , + }, + }, + }, +}; +int nft_table_builtin_add (struct nft_handle *h,struct builtin_table *_t,bool dormant)
iptables/nft.h +9 -0
@@ -38,6 +38,7 @@ struct nft_handle {extern struct builtin_table xtables_ipv4[TABLES_MAX ];extern struct builtin_table xtables_arp[TABLES_MAX ]; +extern struct builtin_table xtables_bridge[TABLES_MAX ]; int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh, int (*cb)(const struct nlmsghdr *nlh, void *data),
@@ -138,6 +139,8 @@ const char *nft_strerror(int err);int do_commandx (struct nft_handle *h,int argc,char *argv[],char **table);/* For xtables-arptables.c */ int do_commandarp (struct nft_handle *h,int argc,char *argv[],char **table); +/* For xtables-eb.c */ +int do_commandeb (struct nft_handle *h,int argc,char *argv[],char **table);/* * Parse config for tables and chain helper functions
@@ -170,4 +173,10 @@ int nft_arp_rule_insert(struct nft_handle *h, const char *chain,void nft_rule_to_arpt_entry (struct nft_rule *r,struct arpt_entry *fw); +/* +* BRIDGE +*/ + +struct ebt_entry ; +#endif
iptables/xtables-eb-standalone.c new file +87 -0
87 lines not on this page · raw message
iptables/xtables-eb.c new file +1122 -0
1,122 lines not on this page · raw message
iptables/xtables-ebtables.h new file +39 -0
@@ -0,0 +1,39 @@ +#ifndef _XTABLES_EBTABLES_H_ +#define _XTABLES_EBTABLES_H_ + +#include <netinet/in.h> +#include <linux/netfilter_bridge/ebtables.h> +#include <linux/netfilter/x_tables.h> + +/* We use replace->flags, so we can't use the following values: +* 0x01 == OPT_COMMAND, 0x02 == OPT_TABLE, 0x100 == OPT_ZERO */ +#define LIST_N 0x04 +#define LIST_C 0x08 +#define LIST_X 0x10 +#define LIST_MAC2 0x20 + +/* Be backwards compatible, so don't use '+' in kernel */ +#define IF_WILDCARD 1 + +int ebt_get_mac_and_mask (const char *from,unsigned char *to,unsigned char *mask); + +struct xtables_ebt_entry +{ +unsigned int bitmask; +unsigned int invflags; +unsigned int flags; +uint16_t ethproto; +char in[IFNAMSIZ ]; +char logical_in[IFNAMSIZ ]; +char out[IFNAMSIZ ]; +char logical_out[IFNAMSIZ ]; +unsigned char sourcemac[ETH_ALEN ]; +unsigned char sourcemsk[ETH_ALEN ]; +unsigned char destmac[ETH_ALEN ]; +unsigned char destmsk[ETH_ALEN ]; +struct xtables_rule_match *matches; +struct xtables_target *target; +struct xt_counters counters; +const char *jumpto; +}; +#endif
iptables/xtables-multi.c +1 -0
@@ -43,6 +43,7 @@ static const struct subcommand multi_subcommands[] = { {"xtables-config", xtables_config_main}, {"xtables-events", xtables_events_main}, {"xtables-arp", xtables_arp_main}, + {"xtables-eb", xtables_eb_main}, #endif {NULL}, };
iptables/xtables-multi.h +1 -0
@@ -8,5 +8,6 @@ extern int xtables_restore_main(int, char **);extern int xtables_config_main (int ,char **);extern int xtables_events_main (int ,char **);extern int xtables_arp_main (int ,char **); +extern int xtables_eb_main (int ,char **);#endif /* _XTABLES_MULTI_H */
Signature · 1 line
1.8.1.5
Re: [PATCH 1/2] xtables: bootstrap xtables-eb for nftables
I made these changes, if I am not wrong now is possible to parse target and match using libxtables:
iptables/xtables-eb.c +0 -0
@@ -459,6 +459,8 @@ int do_commandeb(struct nft_handle *h, int argc,
char *argv[], char **table)
int rulenum_end = 0;
int ret = 0;
struct xtables_target *t;+ struct xtables_rule_match *matchp = NULL;
+ struct xtables_match *m = NULL;
memset(&fw, 0, sizeof(fw));
@@ -925,19 +927,23 @@ big_iface_length:
continue;
default:
/* Is it a target option? */- /*t = (struct ebt_u_target *)new_entry->t;
- if ((t->parse(c - t->option_offset, argv,
argc, new_entry, &t->flags, &t->t))) {
- if (ebt_errormsg[0] != '\0')
- return -1;
+ if (fw.target) {
+ xtables_option_tpcall(c, argv,
fw.invflags, fw.target, &fw);
goto check_extension;- }*/
+ }
/* Is it a match_option? */
- /*for (m = ebt_matches; m; m = m->next)
- if (m->parse(c - m->option_offset,
argv, argc, new_entry, &m->flags, &m->m))
- break;
+ for (matchp = fw.matches; matchp; matchp =matchp->next) {
+ m = matchp->match;
+
+ if (matchp->completed ||
+ (m->x6_parse == NULL && m->parse == NULL))
+ continue;
+
+ xtables_option_mpcall(c, argv,
fw.invflags, m, &fw);
+ }
- if (m != NULL) {
+ /*if (m != NULL) {
if (ebt_errormsg[0] != '\0')
return -1;
if (m->used == 0) {PATCH 2/2 Operations for bridge family
In reply to Giuseppe LongoThe following patch implements the operations for bridge family.
--- iptables/Makefile.am | 2 +- iptables/nft-bridge.c | 384 ++++++++++++++++++++++++++++++++++++++++++++++++++ iptables/nft-shared.c | 3 + iptables/nft.h | 5 +- 4 files changed, 392 insertions(+), 2 deletions(-) create mode 100644 iptables/nft-bridge.c
iptables/Makefile.am +1 -1
@@ -31,7 +31,7 @@ xtables_multi_SOURCES += xtables-config-parser.y xtables-config-syntax.l xtables_multi_SOURCES += xtables-save.c xtables-restore.c \ xtables-standalone.c xtables.c nft.c \ nft-shared.c nft-ipv4.c nft-ipv6.c nft-arp.c \ - xtables-config.c xtables-events.c \ + nft-bridge.c xtables-config.c xtables-events.c \ xtables-arp-standalone.c xtables-arp.c \ getethertype.c nft-bridge.c \ xtables-eb-standalone.c xtables-eb.c
iptables/nft-bridge.c new file +384 -0
384 lines not on this page · raw message
iptables/nft-shared.c +3 -0
@@ -32,6 +32,7 @@extern struct nft_family_ops nft_family_ops_ipv4;extern struct nft_family_ops nft_family_ops_ipv6;extern struct nft_family_ops nft_family_ops_arp; +extern struct nft_family_ops nft_family_ops_bridge;void add_meta (struct nft_rule *r,uint32_t key) {
@@ -649,6 +650,8 @@ struct nft_family_ops *nft_family_ops_lookup(int family)return &nft_family_ops_ipv6;case NFPROTO_ARP :return &nft_family_ops_arp; +case NFPROTO_BRIDGE : +return &nft_family_ops_bridge;default :break ; }
iptables/nft.h +4 -1
@@ -177,6 +177,9 @@ void nft_rule_to_arpt_entry(struct nft_rule *r, struct arpt_entry *fw);* BRIDGE */ -struct ebt_entry ; +#include "xtables-ebtables.h" +struct xtables_ebt_entry ; + +void nft_rule_to_xtables_ebt_entry (struct nft_rule *r,struct xtables_ebt_entry *fw);#endif
Signature · 1 line
1.8.1.5
Giuseppe Longo schreef op 5/02/2014 19:17:
Quoted 27 lines
Hi,
this patchset implements ebtables for the nftables compatibility layer. I would explain some points:
- I didn't figure out how to replace some parts of codes, for istance:from xtables-eb.c, line 928: t = (struct ebt_u_target *)new_entry->t; if ((t->parse(c - t->option_offset, argv, argc, new_entry, &t->flags, &t->t))) { if (ebt_errormsg[0] != '\0') return -1; goto check_extension; } /* Is it a match_option? */ for (m = ebt_matches; m; m = m->next) if (m->parse(c - m->option_offset, argv, argc, new_entry, &m->flags, &m->m)) break; if (m != NULL) { if (ebt_errormsg[0] != '\0') return -1; if (m->used == 0) { ebt_add_match(new_entry, m); m->used = 1; } goto check_extension; }
Quoted 1 line
Looking at extensions, I noticed that any xtables_match/xtables_target have parse functions. Maybe I'm wrong.
The parse functions of the targets/matches/watchers will return 0 if the command-line argument isn't one of their options. If the parse function returns a non-zero value, the command line option belongs to that target/match/watcher. So, unless you don't want support for target/watcher/match command-line arguments, you will need that code.
Quoted 1 line
Even the code from line 992 is not very clear, about final checks. I don't know if I can remove this part of code.
The code you commented out checks for loops in the call chain and runs the final_check functions of the target/matches/watchers. As an example, the ebt_ip module's final_check function makes sure the Ethernet protocol is specified to be IPv4.
I see you comment out more stuff below that. All I can tell you is that it sure is required for correct behavior in the oldschool ebtables program. Please take the time to figure this out (read the code comments, step through the code with a debugger) because I doubt this will be a smooth and stable integration process otherwise.
cheers,
Bart
Hi Bart,
thank you for your explanation, I have to figure out how to port the extensions to xtables.
It's more clearer now.
Cheers,
Giuseppe
2014-02-05 Bart De Schuymer <[email protected]>:
Quoted 60 lines
Giuseppe Longo schreef op 5/02/2014 19:17:
Quoted 30 lines
Hi,
this patchset implements ebtables for the nftables compatibility layer. I would explain some points:
- I didn't figure out how to replace some parts of codes, for istance:from xtables-eb.c, line 928: t = (struct ebt_u_target *)new_entry->t; if ((t->parse(c - t->option_offset, argv, argc, new_entry, &t->flags, &t->t))) { if (ebt_errormsg[0] != '\0') return -1; goto check_extension;}
/* Is it a match_option? */ for (m = ebt_matches; m; m = m->next) if (m->parse(c - m->option_offset, argv, argc, new_entry, &m->flags, &m->m)) break;if (m != NULL) { if (ebt_errormsg[0] != '\0') return -1; if (m->used == 0) { ebt_add_match(new_entry, m); m->used = 1; } goto check_extension; }Quoted 2 lines
Looking at extensions, I noticed that any xtables_match/xtables_target have parse functions. Maybe I'm wrong.
The parse functions of the targets/matches/watchers will return 0 if the command-line argument isn't one of their options. If the parse function returns a non-zero value, the command line option belongs to that target/match/watcher. So, unless you don't want support for target/watcher/match command-line arguments, you will need that code.
Quoted 2 lines
Even the code from line 992 is not very clear, about final checks. I don't know if I can remove this part of code.
The code you commented out checks for loops in the call chain and runs the
final_checkfunctions of the target/matches/watchers. As an example, theebt_ipmodule'sfinal_checkfunction makes sure the Ethernet protocol is specified to be IPv4.
I see you comment out more stuff below that. All I can tell you is that it sure is required for correct behavior in the oldschool ebtables program. Please take the time to figure this out (read the code comments, step through the code with a debugger) because I doubt this will be a smooth and stable integration process otherwise.cheers,
Bart