ebtables patchset
Subsystems (2)
cover ebtables patchset
Hi Pablo,
I reworked the patchset.
The basic operations (-A/-I/-L/-D) are working,
see the examples below:
ebtables-compat -A INPUT -i eth0 -j ACCEPT ebtables-compat -A INPUT -p arp -s 11:22:33:44:55:66 -j ACCEPT ebtables-compat -A INPUT -p arp -d 11:22:33:44:55:66 -j ACCEPT ebtables-compat -L --Ln
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 -i eth0 -j ACCEPT
2 -p ARP -s 11:22:33:44:55:66/0:0:0:0:0:0 -j ACCEPT 3 -p ARP -d 11:22:33:44:55:66/0:0:0:0:0:0 -j ACCEPT
ebtables-compat -D INPUT 2:3
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 -i eth0 -j ACCEPT
As you can see, a minor issue have to be fixed when printing rules. I have no idea how to handle --logical-in/out interfaces currently, so please let me know if you have an idea or an advice.
Giuseppe Longo (3):
xtables: bootstrap xtables-eb for nftables
Operations for bridge family
nft-shared: make compare_matches as public
include/linux/netfilter_bridge.h | 33 + include/linux/netfilter_bridge/ebtables.h | 276 +++++++ include/linux/netfilter_bridge/ethernetdb.h | 58 ++ iptables/Makefile.am | 4 +- iptables/getethertype.c | 161 ++++ iptables/nft-bridge.c | 439 ++++++++++ iptables/nft-shared.c | 7 +- iptables/nft-shared.h | 1 + iptables/nft.c | 28 + iptables/nft.h | 12 + iptables/xtables-compat-multi.c | 1 + iptables/xtables-eb-standalone.c | 87 ++ iptables/xtables-eb.c | 1164 +++++++++++++++++++++++++++ iptables/xtables-ebtables.h | 49 ++ iptables/xtables-multi.c | 1 + iptables/xtables-multi.h | 1 + 16 files changed, 2319 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.3.2
PATCH 1/3 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 | 4 +- iptables/getethertype.c | 161 ++++ iptables/nft.c | 28 + iptables/nft.h | 9 + iptables/xtables-compat-multi.c | 1 + iptables/xtables-eb-standalone.c | 87 ++ iptables/xtables-eb.c | 1164 +++++++++++++++++++++++++++ iptables/xtables-ebtables.h | 49 ++ iptables/xtables-multi.c | 1 + iptables/xtables-multi.h | 1 + 13 files changed, 1871 insertions(+), 1 deletion(-) 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 +3 -1
@@ -39,7 +39,9 @@ xtables_compat_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_compat_multi_LDADD += ${libmnl_LIBS} ${libnftnl_LIBS} # yacc and lex generate dirty code xtables_compat_multi-xtables-config-parser.o xtables_compat_multi-xtables-config-syntax.o: AM_CFLAGS += -Wno-missing-prototypes -Wno-missing-declarations -Wno-implicit-function-declaration -Wno-nested-externs -Wno-undef -Wno-redundant-decls
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
@@ -40,6 +40,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),
@@ -140,6 +141,8 @@ const char *nft_strerror(int err);int do_commandx (struct nft_handle *h,int argc,char *argv[],char **table,bool restore);/* 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
@@ -172,4 +175,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-compat-multi.c +1 -0
@@ -28,6 +28,7 @@ static const struct subcommand multi_subcommands[] = { {"ip6tables-compat-restore", xtables_ip6_restore_main}, {"arptables", xtables_arp_main}, {"arptables-compat", xtables_arp_main}, + {"ebtables-compat", xtables_eb_main}, {"xtables-config", xtables_config_main}, {"xtables-events", xtables_events_main}, {NULL},
iptables/xtables-eb-standalone.c new file +87 -0
87 lines not on this page · raw message
iptables/xtables-eb.c new file +1164 -0
1,164 lines not on this page · raw message
iptables/xtables-ebtables.h new file +49 -0
49 lines not on this page · raw message
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
@@ -10,6 +10,7 @@ extern int xtables_ip6_main(int, char **);extern int xtables_ip6_save_main (int ,char **);extern int xtables_ip6_restore_main (int ,char **);extern int xtables_arp_main (int ,char **); +extern int xtables_eb_main (int ,char **);extern int xtables_config_main (int ,char **);extern int xtables_events_main (int ,char **);#endif
Signature · 1 line
1.8.3.2
PATCH 2/3 Operations for bridge family
In reply to Giuseppe LongoThe following patch implements the operations for bridge family.
--- iptables/nft-bridge.c | 439 ++++++++++++++++++++++++++++++++++++++++++++++++++ iptables/nft-shared.c | 3 + iptables/nft.h | 5 +- 3 files changed, 446 insertions(+), 1 deletion(-) create mode 100644 iptables/nft-bridge.c
iptables/nft-bridge.c new file +439 -0
@@ -0,0 +1,439 @@ +/* +* (C) 2013 by Giuseppe Longo <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <netinet/ether.h> + +#include <xtables.h> +#include <libiptc/libxtc.h> +#include <linux/netfilter/nf_tables.h> +#include <linux/netfilter_bridge/ethernetdb.h> + +#include "nft-shared.h" +#include "nft.h" + +/* 0: default, print only 2 digits if necessary +* 2: always print 2 digits, a printed mac address +* then always has the same length */ +int ebt_printstyle_mac; + +static void ebt_print_mac (const unsigned char *mac) +{ +if (ebt_printstyle_mac ==2 ) { +int j; +for (j =0 ; j <ETH_ALEN ; j++) +printf ("%02x%s" , mac[j], + (j ==ETH_ALEN -1 ) ?"" :":" ); + }else +printf ("%s" ,ether_ntoa ((struct ether_addr *) mac)); +} + +/* Put the mac address into 6 (ETH_ALEN) bytes returns 0 on success. */ +static void ebt_print_mac_and_mask (const unsigned char *mac, +const unsigned char *mask) +{ +char hlpmsk[6 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff }; + +if (!memcmp (mac, eb_mac_type_unicast,6 ) && + !memcmp (mask, eb_msk_type_unicast,6 )) +printf ("Unicast" ); +else if (!memcmp (mac, eb_mac_type_multicast,6 ) && + !memcmp (mask, eb_msk_type_multicast,6 )) +printf ("Multicast" ); +else if (!memcmp (mac, eb_mac_type_broadcast,6 ) && + !memcmp (mask, eb_msk_type_broadcast,6 )) +printf ("Broadcast" ); +else if (!memcmp (mac, eb_mac_type_bridge_group,6 ) && + !memcmp (mask, eb_msk_type_bridge_group,6 )) +printf ("BGA" ); +else { +ebt_print_mac (mac); +if (memcmp (mask, hlpmsk,6 )) { +printf ("/" ); +ebt_print_mac (mask); + } + } +} + +static uint8_t ebt_to_ipt_flags (uint16_t invflags) +{ +uint8_t result =0 ; + +if (invflags &EBT_IIN ) + result |=IPT_INV_VIA_IN ; + +if (invflags &EBT_IOUT ) + result |=IPT_INV_VIA_OUT ; + +if (invflags &EBT_IPROTO ) + result |=IPT_INV_PROTO ; + +if (invflags &EBT_INV_MASK ) + result |=IPT_INV_MASK ; + +return result; +} + +static uint16_t ipt_to_ebt_flags (uint8_t invflags) +{ +uint16_t result =0 ; + +if (invflags &IPT_INV_VIA_IN ) + result |=EBT_IIN ; + +if (invflags &IPT_INV_VIA_OUT ) + result |=EBT_IOUT ; + +if (invflags &IPT_INV_PROTO ) + result |=EBT_IPROTO ; + +if (invflags &IPT_INV_MASK ) + result |=EBT_INV_MASK ; + +return result; +} + +static int _add_action (struct nft_rule *r,struct xtables_ebt_entry *fw) +{ +int ret =0 ; + +/* If no target at all, add nothing (default to continue) */ +if (fw->target !=NULL ) { +/* Standard target? */ +if (!strcmp (fw->jumpto,XTC_LABEL_ACCEPT )) + ret =add_verdict (r,NF_ACCEPT ); +else if (!strcmp (fw->jumpto,XTC_LABEL_DROP )) + ret =add_verdict (r,NF_DROP ); +else if (!strcmp (fw->jumpto,XTC_LABEL_RETURN )) + ret =add_verdict (r,NFT_RETURN ); +else + ret =add_target (r, fw->target->t); + }else if (strlen (fw->jumpto) >0 ) +/* Not standard, then it's a jump to chain */ + ret =add_jumpto (r, fw->jumpto,NFT_JUMP ); + +return ret; +} + +static int nft_bridge_add (struct nft_rule *r,void *data) +{ +struct xtables_ebt_entry *fw = data; +uint8_t flags =ebt_to_ipt_flags (fw->invflags); +char *addr; + +if (fw->in[0 ] !='\0' ) +add_iniface (r, fw->in, flags); + +if (fw->out[0 ] !='\0' ) +add_outiface (r, fw->out, flags); + +if (fw->logical_in[0 ] !='\0' ) +add_iniface (r, fw->logical_in, flags); + +if (fw->logical_out[0 ] !='\0' ) +add_outiface (r, fw->logical_out, flags); + + addr =ether_ntoa ((struct ether_addr *) fw->sourcemac); +if (strcmp (addr,"0:0:0:0:0:0" )) { +add_payload (r, offsetof(struct ethhdr , h_source),6 ); +add_cmp_ptr (r,NFT_CMP_EQ , fw->sourcemac,6 ); + } + + addr =ether_ntoa ((struct ether_addr *) fw->destmac); +if (strcmp (addr,"0:0:0:0:0:0" )) { +add_payload (r, offsetof(struct ethhdr , h_dest),6 ); +add_cmp_ptr (r,NFT_CMP_EQ , fw->destmac,6 ); + } + +if (fw->ethproto !=0 ) { +add_payload (r, offsetof(struct ethhdr , h_proto),2 ); +add_cmp_u16 (r, fw->ethproto,NFT_CMP_EQ ); + } + +return _add_action (r, fw); +} + +static void nft_bridge_parse_meta (struct nft_rule_expr *e,uint8_t key, +void *data) +{ +struct xtables_ebt_entry *fw = data; +uint8_t flags =0 ; + +parse_meta (e, key, fw->in, fw->sourcemsk, + fw->out, fw->destmsk, &flags); + + fw->invflags |=ipt_to_ebt_flags (flags); +} + +static void nft_bridge_parse_payload (struct nft_rule_expr_iter *iter, +uint32_t offset,void *data) +{ +struct xtables_ebt_entry *fw = data; + +switch (offset) { +unsigned char addr[ETH_ALEN ]; +unsigned short int ethproto; +bool inv; +int i; + +case offsetof(struct ethhdr , h_dest): +get_cmp_data (iter, addr,sizeof (addr), &inv); +for (i =0 ; i <ETH_ALEN ; i++) + fw->destmac[i] = addr[i]; +break ; +case offsetof(struct ethhdr , h_source): +get_cmp_data (iter, addr,sizeof (addr), &inv); +for (i =0 ; i <ETH_ALEN ; i++) + fw->sourcemac[i] = addr[i]; +break ; +case offsetof(struct ethhdr , h_proto): +get_cmp_data (iter, ðproto,sizeof (ethproto), &inv); + fw->ethproto = ethproto; +break ; + } +} +static void nft_bridge_parse_immediate (const char *jumpto,bool nft_goto, +void *data) +{ +struct xtables_ebt_entry *fw = data; + + fw->jumpto = jumpto; +} + +static void nft_bridge_parse_target (struct xtables_target *t,void *data) +{ +struct xtables_ebt_entry *fw = data; + + fw->target = t; +} + +void nft_rule_to_xtables_ebt_entry (struct nft_rule *r, +struct xtables_ebt_entry *fw) +{ +struct nft_rule_expr_iter *iter; +struct nft_rule_expr *expr; +int family =nft_rule_attr_get_u8 (r,NFT_RULE_ATTR_FAMILY ); + + iter =nft_rule_expr_iter_create (r); +if (iter ==NULL ) +return ; + + expr =nft_rule_expr_iter_next (iter); +while (expr !=NULL ) { +const char *name = +nft_rule_expr_get_str (expr,NFT_RULE_EXPR_ATTR_NAME ); + +if (strcmp (name,"counter" ) ==0 ) +nft_parse_counter (expr, iter, &fw->counters); +else if (strcmp (name,"payload" ) ==0 ) +nft_parse_payload (expr, iter, family, fw); +else if (strcmp (name,"meta" ) ==0 ) +nft_parse_meta (expr, iter, family, fw); +else if (strcmp (name,"immediate" ) ==0 ) +nft_parse_immediate (expr, iter, family, fw); +else if (strcmp (name,"target" ) ==0 ) +nft_parse_target (expr, iter, family, fw); + + expr =nft_rule_expr_iter_next (iter); + } + +nft_rule_expr_iter_destroy (iter); + +if (fw->target !=NULL ) + fw->jumpto = fw->target->name; +else if (fw->jumpto !=NULL ) + fw->target =xtables_find_target (fw->jumpto,XTF_TRY_LOAD ); +else + fw->jumpto ="" ; +} + +static void print_iface (const char *iface) +{ +char *c; + + c =strchr (iface,IF_WILDCARD ); +if (c) + *c ='+' ; +printf ("%s " , iface); +if (c) + *c =IF_WILDCARD ; +} + +static void +nft_bridge_print_firewall (struct nft_rule *r,unsigned int num, +unsigned int format) +{ +struct xtables_ebt_entry fw = {}; +char *addr; + +nft_rule_to_xtables_ebt_entry (r, &fw); + +if (format &FMT_LINENUMBERS ) +printf ("%d " , num); + +/* Dont print anything about the protocol if no protocol was +* specified, obviously this means any protocol will do. */ +if (fw.ethproto !=0 ) { +printf ("-p " ); +if (fw.invflags &EBT_IPROTO ) +printf ("! " ); +if (fw.bitmask &EBT_802_3 ) +printf ("Length " ); +else { +struct ethertypeent *ent; + + ent =getethertypebynumber (ntohs (fw.ethproto)); +if (!ent) +printf ("0x%x " ,ntohs (fw.ethproto)); +else +printf ("%s " , ent->e_name); + } + } + + addr =ether_ntoa ((struct ether_addr *) fw.sourcemac); +if (strcmp (addr,"0:0:0:0:0:0" )) { +printf ("-s " ); +if (fw.invflags &EBT_ISOURCE ) +printf ("! " ); +ebt_print_mac_and_mask (fw.sourcemac, fw.sourcemsk); +printf (" " ); + } + + addr =ether_ntoa ((struct ether_addr *) fw.destmac); +if (strcmp (addr,"0:0:0:0:0:0" )) { +printf ("-d " ); +if (fw.invflags &EBT_IDEST ) +printf ("! " ); +ebt_print_mac_and_mask (fw.destmac, fw.destmsk); +printf (" " ); + } + +if (fw.in[0 ] !='\0' ) { +printf ("-i " ); +if (fw.invflags &EBT_IIN ) +printf ("! " ); +print_iface (fw.in); + } + +if (fw.logical_in[0 ] !='\0' ) { +printf ("--logical-in " ); +if (fw.invflags &EBT_ILOGICALIN ) +printf ("! " ); +print_iface (fw.logical_in); + } + +if (fw.logical_out[0 ] !='\0' ) { +printf ("--logical-out " ); +if (fw.invflags &EBT_ILOGICALOUT ) +printf ("! " ); +print_iface (fw.logical_out); + } + +if (fw.out[0 ] !='\0' ) { +printf ("-o " ); +if (fw.invflags &EBT_IOUT ) +printf ("! " ); +print_iface (fw.out); + } + +/* old code to adapt +m_l = hlp->m_list; +while (m_l) { +m = ebt_find_match(m_l->m->u.name); +if (!m) +ebt_print_bug("Match not found"); +m->print(hlp, m_l->m); +m_l = m_l->next; +} +w_l = hlp->w_list; +while (w_l) { +w = ebt_find_watcher(w_l->w->u.name); +if (!w) +ebt_print_bug("Watcher not found"); +w->print(hlp, w_l->w); +w_l = w_l->next; +}*/ +printf ("-j " ); +if (!(format &FMT_NOTARGET )) +printf ("%s" , fw.jumpto); + +if (fw.target !=NULL ) { +if (fw.target->print !=NULL ) { + fw.target->FMT_NUMERIC ); + } + } + +if (!(format &FMT_NONEWLINE )) +fputc ('\n' , stdout); +} + +static bool nft_bridge_is_same (const void *data_a, +const void *data_b) +{ +const struct xtables_ebt_entry *a = data_a; +const struct xtables_ebt_entry *b = data_b; + +if (a->ethproto != b->ethproto + || a->flags != b->flags + || a->invflags != b->invflags) { +DEBUGP ("different proto/flags/invflags\n" ); +return false; + } + +return is_same_interfaces (a->in, a->out, a->in_mask, a->out_mask, + b->in, b->out, b->in_mask, b->out_mask); +} + +static bool nft_bridge_rule_find (struct nft_family_ops *ops,struct nft_rule *r, +void *data) +{ +struct xtables_ebt_entry *fw = data; +struct xtables_ebt_entry this; + +nft_rule_to_xtables_ebt_entry (r, &this); + +DEBUGP ("comparing with... " ); + +if (!ops->is_same (fw, &this)) +return false; + +if (!compare_matches (fw->matches, this.matches)) { +DEBUGP ("Different matches\n" ); +return false; + } + +if (!compare_targets (fw->target, this.target)) { +DEBUGP ("Different target\n" ); +return false; + } + +if (strcmp (fw->jumpto, this.jumpto) !=0 ) { +DEBUGP ("Different verdict\n" ); +return false; + } + +return true; +} + +struct nft_family_ops nft_family_ops_bridge = { + .add = nft_bridge_add, + .is_same = nft_bridge_is_same, + .print_payload =NULL , + .parse_meta = nft_bridge_parse_meta, + .parse_payload = nft_bridge_parse_payload, + .parse_immediate = nft_bridge_parse_immediate, + .print_firewall = nft_bridge_print_firewall, + .post_parse =NULL , + .rule_find = nft_bridge_rule_find, + .parse_target = nft_bridge_parse_target, +};
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) {
@@ -680,6 +681,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
@@ -179,6 +179,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.3.2
PATCH 3/3 nft-shared: make compare_matches as public
In reply to Giuseppe LongoThis permits to compare two xtables_ebt_entry's matches reusing compare_matches.
--- iptables/nft-shared.c | 4 ++-- iptables/nft-shared.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
iptables/nft-shared.c +2 -2
@@ -690,8 +690,8 @@ struct nft_family_ops *nft_family_ops_lookup(int family)return NULL ; } -static bool -compare_matches (struct xtables_rule_match *mt1,struct xtables_rule_match *mt2) +bool compare_matches (struct xtables_rule_match *mt1, +struct xtables_rule_match *mt2) {struct xtables_rule_match *mp1;struct xtables_rule_match *mp2;
iptables/nft-shared.h +1 -0
@@ -128,6 +128,7 @@ struct nft_handle;bool nft_ipv46_rule_find (struct nft_family_ops *ops,struct nft_rule *r,struct iptables_command_state *cs); +bool compare_matches (struct xtables_rule_match *mt1,struct xtables_rule_match *mt2);bool compare_targets (struct xtables_target *tg1,struct xtables_target *tg2);struct addr_mask {
Signature · 1 line
1.8.3.2
Re: [iptables 3/3] nft-shared: make compare_matches as public
iptables/nft-shared.c struct nft_family_ops *nft_family_ops_lookup(int family) · line 694
Quoted 2 lines · On Fri, 7 Mar 2014 20:33:25 +0100 Giuseppe Longo <[email protected]> wrote:
iptables/nft-shared.c +2
-0+bool compare_matches (struct xtables_rule_match *mt1, +struct xtables_rule_match *mt2)
any function exposed as global should have a name that uses a prefix, something like nft_compare_matches or xt_compare_matches
The kernel is linked as single C application and this avoids future name conflicts.
Hi Pablo and Giuseppe,
Quoted 3 lines
As you can see, a minor issue have to be fixed when printing rules. I have no idea how to handle --logical-in/out interfaces currently, so please let me know if you have an idea or an advice.
As far as I know, there is nothing in nftables's side to differentiate between interfaces origin, right? (like a proper hw tight 'eth0' vs a bridge 'br0') Unless I miss something, it has no real meaning in nftables to support such differentiation, but for the sake of ebtables compat layer we might need a solution here.
Any idea how this issue could be fixed?
Br,
Tomasz
Pablo Neira Ayuso
maintainerQuoted 6 lines · Tomasz Bursztyka
Hi Pablo and Giuseppe,
Quoted 3 lines
As you can see, a minor issue have to be fixed when printing rules. I have no idea how to handle --logical-in/out interfaces currently, so please let me know if you have an idea or an advice.
Quoted 8 lines
As far as I know, there is nothing in nftables's side to differentiate between interfaces origin, right? (like a proper hw tight 'eth0' vs a bridge 'br0')
Unless I miss something, it has no real meaning in nftables to support such differentiation,
but for the sake of ebtables compat layer we might need a solution here.Any idea how this issue could be fixed?
I think you have to extend nft_meta to support that. See ebt_basic_match(), the net_bridge_port information is obtained via br_port_get_rcu(dev) given that dev != NULL.
Beware that you have to make sure that the new meta types IIFBRNAME and OIFBRNAME can only be used from the bridge family. I think you have to do something similar to what Patrick did with nft_reject, by adding a specific flavour of nft_meta for the bridge family.
Giuseppe, what other remaining issues you have with the ebtables compat layer? Could you summarize them, please? Thanks.
2014-03-24 16:09 GMT+01:00 Pablo Neira Ayuso <[email protected]>:
Quoted 20 lines · Tomasz Bursztyka
Quoted 6 lines
Hi Pablo and Giuseppe,
Quoted 3 lines
As you can see, a minor issue have to be fixed when printing rules. I have no idea how to handle --logical-in/out interfaces currently, so please let me know if you have an idea or an advice.
Quoted 8 lines
As far as I know, there is nothing in nftables's side to differentiate between interfaces origin, right? (like a proper hw tight 'eth0' vs a bridge 'br0')
Unless I miss something, it has no real meaning in nftables to support such differentiation,
but for the sake of ebtables compat layer we might need a solution here.Any idea how this issue could be fixed?
I think you have to extend
nft_metato support that. Seeebt_basic_match(), thenet_bridge_portinformation is obtained viabr_port_get_rcu(dev)given that dev != NULL.
Quoted 7 lines
Beware that you have to make sure that the new meta types IIFBRNAME and OIFBRNAME can only be used from the bridge family. I think you have to do something similar to what Patrick did with
nft_reject, by adding a specific flavour ofnft_metafor the bridge family.Giuseppe, what other remaining issues you have with the ebtables compat layer? Could you summarize them, please? Thanks.
Hi Pablo,
minor issues to fix:
- when printing rules, the mask is printed when it shouldn't be, see below:
Chain INPUT (policy ACCEPT)
target prot opt source destination
-s 11:22:33:44:55:66/0:0:0:0:0:0 -j ACCEPT
- nft_bridge_is_same not works properly
- a rule can be deleted only if the number is specified (caused by point above)
There are no other issues currently
Hi Pablo,
Quoted 8 lines
I think you have to extend
nft_metato support that. Seeebt_basic_match(), thenet_bridge_portinformation is obtained viabr_port_get_rcu(dev)given that dev != NULL.Beware that you have to make sure that the new meta types IIFBRNAME and OIFBRNAME can only be used from the bridge family. I think you have to do something similar to what Patrick did with
nft_reject, by adding a specific flavour ofnft_metafor the bridge family.
Indeed. Will prepare something quick
Thanks,
Tomasz
Hi Pablo,
Quoted 3 lines
I think you
have to do something similar to what Patrick did withnft_reject, by adding a specific flavour ofnft_metafor the bridge family.
In case of nft_meta, it would mean quite much code change,
since most of the keys are valid also for NFPROTO_BRIDGE.
Or maybe I miss something. (I don't know if it's proper to register a second expr in the same nft_meta.c, dedicated to bridge)
Wouldn't it be easier if I just check ctx->afi->family to be NFPROTO_BRIDGE in nft_meta_init if the given key is one of the bridge related?
At evaluation, I can still check pkt->ops->pf as well.
Does the logic sound relevant?
Tomasz