Skip to content

Commit e385357

Browse files
Jozsef Kadlecsikkaber
authored andcommitted
netfilter: ipset: hash:net,iface type introduced
The hash:net,iface type makes possible to store network address and interface name pairs in a set. It's mostly suitable for egress and ingress filtering. Examples: # ipset create test hash:net,iface # ipset add test 192.168.0.0/16,eth0 # ipset add test 192.168.0.0/24,eth1 Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> Signed-off-by: Patrick McHardy <kaber@trash.net>
1 parent 9b03a5e commit e385357

5 files changed

Lines changed: 784 additions & 0 deletions

File tree

include/linux/netfilter/ipset/ip_set.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ enum {
105105
IPSET_ATTR_IP2,
106106
IPSET_ATTR_CIDR2,
107107
IPSET_ATTR_IP2_TO,
108+
IPSET_ATTR_IFACE,
108109
__IPSET_ATTR_ADT_MAX,
109110
};
110111
#define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
@@ -153,6 +154,8 @@ enum ipset_cmd_flags {
153154
enum ipset_cadt_flags {
154155
IPSET_FLAG_BIT_BEFORE = 0,
155156
IPSET_FLAG_BEFORE = (1 << IPSET_FLAG_BIT_BEFORE),
157+
IPSET_FLAG_BIT_PHYSDEV = 1,
158+
IPSET_FLAG_PHYSDEV = (1 << IPSET_FLAG_BIT_PHYSDEV),
156159
};
157160

158161
/* Commands with settype-specific attributes */
@@ -212,6 +215,8 @@ enum ip_set_feature {
212215
IPSET_TYPE_IP2 = (1 << IPSET_TYPE_IP2_FLAG),
213216
IPSET_TYPE_NAME_FLAG = 4,
214217
IPSET_TYPE_NAME = (1 << IPSET_TYPE_NAME_FLAG),
218+
IPSET_TYPE_IFACE_FLAG = 5,
219+
IPSET_TYPE_IFACE = (1 << IPSET_TYPE_IFACE_FLAG),
215220
/* Strictly speaking not a feature, but a flag for dumping:
216221
* this settype must be dumped last */
217222
IPSET_DUMP_LAST_FLAG = 7,

include/linux/netfilter/ipset/ip_set_ahash.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct ip_set_hash {
6363
#ifdef IP_SET_HASH_WITH_NETMASK
6464
u8 netmask; /* netmask value for subnets to store */
6565
#endif
66+
#ifdef IP_SET_HASH_WITH_RBTREE
67+
struct rb_root rbtree;
68+
#endif
6669
#ifdef IP_SET_HASH_WITH_NETS
6770
struct ip_set_hash_nets nets[0]; /* book-keeping of prefixes */
6871
#endif
@@ -200,6 +203,9 @@ ip_set_hash_destroy(struct ip_set *set)
200203
del_timer_sync(&h->gc);
201204

202205
ahash_destroy(h->table);
206+
#ifdef IP_SET_HASH_WITH_RBTREE
207+
rbtree_destroy(&h->rbtree);
208+
#endif
203209
kfree(h);
204210

205211
set->data = NULL;

net/netfilter/ipset/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ config IP_SET_HASH_NETPORT
109109

110110
To compile it as a module, choose M here. If unsure, say N.
111111

112+
config IP_SET_HASH_NETIFACE
113+
tristate "hash:net,iface set support"
114+
depends on IP_SET
115+
help
116+
This option adds the hash:net,iface set type support, by which
117+
one can store IPv4/IPv6 network address/prefix and
118+
interface name pairs as elements in a set.
119+
120+
To compile it as a module, choose M here. If unsure, say N.
121+
112122
config IP_SET_LIST_SET
113123
tristate "list:set set support"
114124
depends on IP_SET

net/netfilter/ipset/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ obj-$(CONFIG_IP_SET_HASH_IPPORTIP) += ip_set_hash_ipportip.o
1919
obj-$(CONFIG_IP_SET_HASH_IPPORTNET) += ip_set_hash_ipportnet.o
2020
obj-$(CONFIG_IP_SET_HASH_NET) += ip_set_hash_net.o
2121
obj-$(CONFIG_IP_SET_HASH_NETPORT) += ip_set_hash_netport.o
22+
obj-$(CONFIG_IP_SET_HASH_NETIFACE) += ip_set_hash_netiface.o
2223

2324
# list types
2425
obj-$(CONFIG_IP_SET_LIST_SET) += ip_set_list_set.o

0 commit comments

Comments
 (0)