nft: Split nft core to become family independant
PATCH v2 1/1 nft: Split nft core to become family independant
This makes nft core code independant from the family. Each family needs to implement and provide a struct nft_family_ops {}.
This split will ease the future support of bridge and arp rules manipulations.
---
Version 2:
- added (C) headers
- put relevant shared macros in nft-shared.h
iptables/Makefile.am | 1 + iptables/nft-ipv4.c | 315 ++++++++++++++++++ iptables/nft-ipv6.c | 224 +++++++++++++ iptables/nft-shared.c | 426 ++++++++++++++++++++++++ iptables/nft-shared.h | 110 +++++++ iptables/nft.c | 893 +------------------------------------------------- iptables/nft.h | 2 + iptables/xtables.c | 19 +- 8 files changed, 1100 insertions(+), 890 deletions(-) create mode 100644 iptables/nft-ipv4.c create mode 100644 iptables/nft-ipv6.c create mode 100644 iptables/nft-shared.c create mode 100644 iptables/nft-shared.h
iptables/Makefile.am +1 -0
@@ -29,6 +29,7 @@ if HAVE_LIBMNL if HAVE_LIBNFTABLES 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 \ xtables-config-parser.y xtables-config-syntax.l \ xtables-config.c xtables_multi_LDADD += -lmnl -lnftables
iptables/nft-ipv4.c new file +315 -0
315 lines not on this page · raw message
iptables/nft-ipv6.c new file +224 -0
224 lines not on this page · raw message
iptables/nft-shared.c new file +426 -0
426 lines not on this page · raw message
iptables/nft-shared.h new file +110 -0
110 lines not on this page · raw message
iptables/nft.c +18 -875
1,019 lines not on this page · raw message
iptables/nft.h +2 -0
@@ -2,12 +2,14 @@#define _NFT_H_#include "xshared.h" +#include "nft-shared.h" struct nft_handle {int family;struct mnl_socket *nl;uint32_t portid;uint32_t seq; +struct nft_family_ops *ops; };int nft_init (struct nft_handle *h);
iptables/xtables.c +4 -15
@@ -40,6 +40,7 @@#include <xtables.h> #include <fcntl.h> #include "xshared.h" +#include "nft-shared.h" #include "nft.h" #ifndef TRUE
@@ -49,21 +50,6 @@#define FALSE 0#endif -#define FMT_NUMERIC 0x0001 -#define FMT_NOCOUNTS 0x0002 -#define FMT_KILOMEGAGIGA 0x0004 -#define FMT_OPTIONS 0x0008 -#define FMT_NOTABLE 0x0010 -#define FMT_NOTARGET 0x0020 -#define FMT_VIA 0x0040 -#define FMT_NONEWLINE 0x0080 -#define FMT_LINENUMBERS 0x0100 - -#define FMT_PRINT_RULE (FMT_NOCOUNTS | FMT_OPTIONS | FMT_VIA \ - | FMT_NUMERIC | FMT_NOTABLE) -#define FMT (tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab)) - -#define CMD_NONE 0x0000U#define CMD_INSERT 0x0001U#define CMD_DELETE 0x0002U
@@ -1250,6 +1236,9 @@ int do_commandx(struct nft_handle *h, int argc, char *argv[], char **table) } h->family = family; + h->ops =nft_family_ops_lookup (family); +if (h->ops ==NULL ) +xtables_error (PARAMETER_PROBLEM ,"Unknown family" );if (command ==CMD_REPLACE && (s.naddrs !=1 || d.naddrs !=1 )) xtables_error(PARAMETER_PROBLEM, "Replacement rule does not "
Signature · 1 line
1.8.1.1
Pablo Neira Ayuso
maintainerQuoted 4 lines · Tomasz Bursztyka
This makes nft core code independant from the family. Each family needs to implement and provide a struct
nft_family_ops{}.This split will ease the future support of bridge and arp rules manipulations.
Finally applied, thanks a lot Tomasz.