Skip to content

Commit 8522484

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== pull request: netfilter/ipvs updates for net-next The following patchset contains Netfilter/IPVS updates for net-next, most relevantly they are: 1) Four patches to make the new nf_tables masquerading support independent of the x_tables infrastructure. This also resolves a compilation breakage if the masquerade target is disabled but the nf_tables masq expression is enabled. 2) ipset updates via Jozsef Kadlecsik. This includes the addition of the skbinfo extension that allows you to store packet metainformation in the elements. This can be used to fetch and restore this to the packets through the iptables SET target, patches from Anton Danilov. 3) Add the hash:mac set type to ipset, from Jozsef Kadlecsick. 4) Add simple weighted fail-over scheduler via Simon Horman. This provides a fail-over IPVS scheduler (unlike existing load balancing schedulers). Connections are directed to the appropriate server based solely on highest weight value and server availability, patch from Kenny Mathis. 5) Support IPv6 real servers in IPv4 virtual-services and vice versa. Simon Horman informs that the motivation for this is to allow more flexibility in the choice of IP version offered by both virtual-servers and real-servers as they no longer need to match: An IPv4 connection from an end-user may be forwarded to a real-server using IPv6 and vice versa. No ip_vs_sync support yet though. Patches from Alex Gartrell and Julian Anastasov. 6) Add global generation ID to the nf_tables ruleset. When dumping from several different object lists, we need a way to identify that an update has ocurred so userspace knows that it needs to refresh its lists. This also includes a new command to obtain the 32-bits generation ID. The less significant 16-bits of this ID is also exposed through res_id field in the nfnetlink header to quickly detect the interference and retry when there is no risk of ID wraparound. 7) Move br_netfilter out of the bridge core. The br_netfilter code is built in the bridge core by default. This causes problems of different kind to people that don't want this: Jesper reported performance drop due to the inconditional hook registration and I remember to have read complains on netdev from people regarding the unexpected behaviour of our bridging stack when br_netfilter is enabled (fragmentation handling, layer 3 and upper inspection). People that still need this should easily undo the damage by modprobing the new br_netfilter module. 8) Dump the set policy nf_tables that allows set parameterization. So userspace can keep user-defined preferences when saving the ruleset. From Arturo Borrero. 9) Use __seq_open_private() helper function to reduce boiler plate code in x_tables, From Rob Jones. 10) Safer default behaviour in case that you forget to load the protocol tracker. Daniel Borkmann and Florian Westphal detected that if your ruleset is stateful, you allow traffic to at least one single SCTP port and the SCTP protocol tracker is not loaded, then any SCTP traffic may be pass through unfiltered. After this patch, the connection tracking classifies SCTP/DCCP/UDPlite/GRE packets as invalid if your kernel has been compiled with support for these modules. ==================== Trivially resolved conflict in include/linux/skbuff.h, Eric moved some netfilter skbuff members around, and the netfilter tree adjusted the ifdef guards for the bridging info pointer. Signed-off-by: David S. Miller <[email protected]>
2 parents 735d383 + db29a95 commit 8522484

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1595
-512
lines changed

include/linux/netfilter/ipset/ip_set.h

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ enum ip_set_extension {
5757
IPSET_EXT_COUNTER = (1 << IPSET_EXT_BIT_COUNTER),
5858
IPSET_EXT_BIT_COMMENT = 2,
5959
IPSET_EXT_COMMENT = (1 << IPSET_EXT_BIT_COMMENT),
60+
IPSET_EXT_BIT_SKBINFO = 3,
61+
IPSET_EXT_SKBINFO = (1 << IPSET_EXT_BIT_SKBINFO),
6062
/* Mark set with an extension which needs to call destroy */
6163
IPSET_EXT_BIT_DESTROY = 7,
6264
IPSET_EXT_DESTROY = (1 << IPSET_EXT_BIT_DESTROY),
@@ -65,12 +67,14 @@ enum ip_set_extension {
6567
#define SET_WITH_TIMEOUT(s) ((s)->extensions & IPSET_EXT_TIMEOUT)
6668
#define SET_WITH_COUNTER(s) ((s)->extensions & IPSET_EXT_COUNTER)
6769
#define SET_WITH_COMMENT(s) ((s)->extensions & IPSET_EXT_COMMENT)
70+
#define SET_WITH_SKBINFO(s) ((s)->extensions & IPSET_EXT_SKBINFO)
6871
#define SET_WITH_FORCEADD(s) ((s)->flags & IPSET_CREATE_FLAG_FORCEADD)
6972

7073
/* Extension id, in size order */
7174
enum ip_set_ext_id {
7275
IPSET_EXT_ID_COUNTER = 0,
7376
IPSET_EXT_ID_TIMEOUT,
77+
IPSET_EXT_ID_SKBINFO,
7478
IPSET_EXT_ID_COMMENT,
7579
IPSET_EXT_ID_MAX,
7680
};
@@ -92,6 +96,10 @@ struct ip_set_ext {
9296
u64 packets;
9397
u64 bytes;
9498
u32 timeout;
99+
u32 skbmark;
100+
u32 skbmarkmask;
101+
u32 skbprio;
102+
u16 skbqueue;
95103
char *comment;
96104
};
97105

@@ -104,6 +112,13 @@ struct ip_set_comment {
104112
char *str;
105113
};
106114

115+
struct ip_set_skbinfo {
116+
u32 skbmark;
117+
u32 skbmarkmask;
118+
u32 skbprio;
119+
u16 skbqueue;
120+
};
121+
107122
struct ip_set;
108123

109124
#define ext_timeout(e, s) \
@@ -112,7 +127,8 @@ struct ip_set;
112127
(struct ip_set_counter *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COUNTER])
113128
#define ext_comment(e, s) \
114129
(struct ip_set_comment *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COMMENT])
115-
130+
#define ext_skbinfo(e, s) \
131+
(struct ip_set_skbinfo *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_SKBINFO])
116132

117133
typedef int (*ipset_adtfn)(struct ip_set *set, void *value,
118134
const struct ip_set_ext *ext,
@@ -256,6 +272,8 @@ ip_set_put_flags(struct sk_buff *skb, struct ip_set *set)
256272
cadt_flags |= IPSET_FLAG_WITH_COUNTERS;
257273
if (SET_WITH_COMMENT(set))
258274
cadt_flags |= IPSET_FLAG_WITH_COMMENT;
275+
if (SET_WITH_SKBINFO(set))
276+
cadt_flags |= IPSET_FLAG_WITH_SKBINFO;
259277
if (SET_WITH_FORCEADD(set))
260278
cadt_flags |= IPSET_FLAG_WITH_FORCEADD;
261279

@@ -304,6 +322,43 @@ ip_set_update_counter(struct ip_set_counter *counter,
304322
}
305323
}
306324

325+
static inline void
326+
ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo,
327+
const struct ip_set_ext *ext,
328+
struct ip_set_ext *mext, u32 flags)
329+
{
330+
mext->skbmark = skbinfo->skbmark;
331+
mext->skbmarkmask = skbinfo->skbmarkmask;
332+
mext->skbprio = skbinfo->skbprio;
333+
mext->skbqueue = skbinfo->skbqueue;
334+
}
335+
static inline bool
336+
ip_set_put_skbinfo(struct sk_buff *skb, struct ip_set_skbinfo *skbinfo)
337+
{
338+
/* Send nonzero parameters only */
339+
return ((skbinfo->skbmark || skbinfo->skbmarkmask) &&
340+
nla_put_net64(skb, IPSET_ATTR_SKBMARK,
341+
cpu_to_be64((u64)skbinfo->skbmark << 32 |
342+
skbinfo->skbmarkmask))) ||
343+
(skbinfo->skbprio &&
344+
nla_put_net32(skb, IPSET_ATTR_SKBPRIO,
345+
cpu_to_be32(skbinfo->skbprio))) ||
346+
(skbinfo->skbqueue &&
347+
nla_put_net16(skb, IPSET_ATTR_SKBQUEUE,
348+
cpu_to_be16(skbinfo->skbqueue)));
349+
350+
}
351+
352+
static inline void
353+
ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo,
354+
const struct ip_set_ext *ext)
355+
{
356+
skbinfo->skbmark = ext->skbmark;
357+
skbinfo->skbmarkmask = ext->skbmarkmask;
358+
skbinfo->skbprio = ext->skbprio;
359+
skbinfo->skbqueue = ext->skbqueue;
360+
}
361+
307362
static inline bool
308363
ip_set_put_counter(struct sk_buff *skb, struct ip_set_counter *counter)
309364
{
@@ -497,6 +552,9 @@ ip_set_put_extensions(struct sk_buff *skb, const struct ip_set *set,
497552
if (SET_WITH_COMMENT(set) &&
498553
ip_set_put_comment(skb, ext_comment(e, set)))
499554
return -EMSGSIZE;
555+
if (SET_WITH_SKBINFO(set) &&
556+
ip_set_put_skbinfo(skb, ext_skbinfo(e, set)))
557+
return -EMSGSIZE;
500558
return 0;
501559
}
502560

include/linux/netfilter_bridge.h

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum nf_br_hook_priorities {
1515
NF_BR_PRI_LAST = INT_MAX,
1616
};
1717

18-
#ifdef CONFIG_BRIDGE_NETFILTER
18+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1919

2020
#define BRNF_PKT_TYPE 0x01
2121
#define BRNF_BRIDGED_DNAT 0x02
@@ -24,16 +24,6 @@ enum nf_br_hook_priorities {
2424
#define BRNF_8021Q 0x10
2525
#define BRNF_PPPoE 0x20
2626

27-
/* Only used in br_forward.c */
28-
int nf_bridge_copy_header(struct sk_buff *skb);
29-
static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb)
30-
{
31-
if (skb->nf_bridge &&
32-
skb->nf_bridge->mask & (BRNF_BRIDGED | BRNF_BRIDGED_DNAT))
33-
return nf_bridge_copy_header(skb);
34-
return 0;
35-
}
36-
3727
static inline unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb)
3828
{
3929
switch (skb->protocol) {
@@ -46,6 +36,44 @@ static inline unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb)
4636
}
4737
}
4838

39+
static inline void nf_bridge_update_protocol(struct sk_buff *skb)
40+
{
41+
if (skb->nf_bridge->mask & BRNF_8021Q)
42+
skb->protocol = htons(ETH_P_8021Q);
43+
else if (skb->nf_bridge->mask & BRNF_PPPoE)
44+
skb->protocol = htons(ETH_P_PPP_SES);
45+
}
46+
47+
/* Fill in the header for fragmented IP packets handled by
48+
* the IPv4 connection tracking code.
49+
*
50+
* Only used in br_forward.c
51+
*/
52+
static inline int nf_bridge_copy_header(struct sk_buff *skb)
53+
{
54+
int err;
55+
unsigned int header_size;
56+
57+
nf_bridge_update_protocol(skb);
58+
header_size = ETH_HLEN + nf_bridge_encap_header_len(skb);
59+
err = skb_cow_head(skb, header_size);
60+
if (err)
61+
return err;
62+
63+
skb_copy_to_linear_data_offset(skb, -header_size,
64+
skb->nf_bridge->data, header_size);
65+
__skb_push(skb, nf_bridge_encap_header_len(skb));
66+
return 0;
67+
}
68+
69+
static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb)
70+
{
71+
if (skb->nf_bridge &&
72+
skb->nf_bridge->mask & (BRNF_BRIDGED | BRNF_BRIDGED_DNAT))
73+
return nf_bridge_copy_header(skb);
74+
return 0;
75+
}
76+
4977
static inline unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)
5078
{
5179
if (unlikely(skb->nf_bridge->mask & BRNF_PPPoE))

include/linux/skbuff.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct nf_conntrack {
156156
};
157157
#endif
158158

159-
#ifdef CONFIG_BRIDGE_NETFILTER
159+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
160160
struct nf_bridge_info {
161161
atomic_t use;
162162
unsigned int mask;
@@ -534,7 +534,7 @@ struct sk_buff {
534534
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
535535
struct nf_conntrack *nfct;
536536
#endif
537-
#ifdef CONFIG_BRIDGE_NETFILTER
537+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
538538
struct nf_bridge_info *nf_bridge;
539539
#endif
540540
unsigned int len,
@@ -556,8 +556,6 @@ struct sk_buff {
556556
/* one bit hole */
557557
kmemcheck_bitfield_end(flags1);
558558

559-
560-
561559
/* fields enclosed in headers_start/headers_end are copied
562560
* using a single memcpy() in __copy_skb_header()
563561
*/
@@ -3016,7 +3014,7 @@ static inline void nf_conntrack_get(struct nf_conntrack *nfct)
30163014
atomic_inc(&nfct->use);
30173015
}
30183016
#endif
3019-
#ifdef CONFIG_BRIDGE_NETFILTER
3017+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
30203018
static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
30213019
{
30223020
if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
@@ -3034,7 +3032,7 @@ static inline void nf_reset(struct sk_buff *skb)
30343032
nf_conntrack_put(skb->nfct);
30353033
skb->nfct = NULL;
30363034
#endif
3037-
#ifdef CONFIG_BRIDGE_NETFILTER
3035+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
30383036
nf_bridge_put(skb->nf_bridge);
30393037
skb->nf_bridge = NULL;
30403038
#endif
@@ -3057,7 +3055,7 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src,
30573055
if (copy)
30583056
dst->nfctinfo = src->nfctinfo;
30593057
#endif
3060-
#ifdef CONFIG_BRIDGE_NETFILTER
3058+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
30613059
dst->nf_bridge = src->nf_bridge;
30623060
nf_bridge_get(src->nf_bridge);
30633061
#endif
@@ -3072,7 +3070,7 @@ static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src)
30723070
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
30733071
nf_conntrack_put(dst->nfct);
30743072
#endif
3075-
#ifdef CONFIG_BRIDGE_NETFILTER
3073+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
30763074
nf_bridge_put(dst->nf_bridge);
30773075
#endif
30783076
__nf_copy(dst, src, true);

include/net/ip_vs.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ struct ip_vs_conn {
535535
union nf_inet_addr daddr; /* destination address */
536536
volatile __u32 flags; /* status flags */
537537
__u16 protocol; /* Which protocol (TCP/UDP) */
538+
__u16 daf; /* Address family of the dest */
538539
#ifdef CONFIG_NET_NS
539540
struct net *net; /* Name space */
540541
#endif
@@ -648,6 +649,9 @@ struct ip_vs_dest_user_kern {
648649
/* thresholds for active connections */
649650
u32 u_threshold; /* upper threshold */
650651
u32 l_threshold; /* lower threshold */
652+
653+
/* Address family of addr */
654+
u16 af;
651655
};
652656

653657

@@ -986,6 +990,10 @@ struct netns_ipvs {
986990
char backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
987991
/* net name space ptr */
988992
struct net *net; /* Needed by timer routines */
993+
/* Number of heterogeneous destinations, needed because
994+
* heterogeneous are not supported when synchronization is
995+
* enabled */
996+
unsigned int mixed_address_family_dests;
989997
};
990998

991999
#define DEFAULT_SYNC_THRESHOLD 3
@@ -1210,7 +1218,7 @@ static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
12101218
void ip_vs_conn_put(struct ip_vs_conn *cp);
12111219
void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
12121220

1213-
struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
1221+
struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
12141222
const union nf_inet_addr *daddr,
12151223
__be16 dport, unsigned int flags,
12161224
struct ip_vs_dest *dest, __u32 fwmark);
@@ -1396,8 +1404,9 @@ void ip_vs_unregister_nl_ioctl(void);
13961404
int ip_vs_control_init(void);
13971405
void ip_vs_control_cleanup(void);
13981406
struct ip_vs_dest *
1399-
ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
1400-
__be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
1407+
ip_vs_find_dest(struct net *net, int svc_af, int dest_af,
1408+
const union nf_inet_addr *daddr, __be16 dport,
1409+
const union nf_inet_addr *vaddr, __be16 vport,
14011410
__u16 protocol, __u32 fwmark, __u32 flags);
14021411
void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
14031412

include/net/neighbour.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
373373
return 0;
374374
}
375375

376-
#ifdef CONFIG_BRIDGE_NETFILTER
376+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
377377
static inline int neigh_hh_bridge(struct hh_cache *hh, struct sk_buff *skb)
378378
{
379379
unsigned int seq, hh_alen;

include/net/netfilter/ipv4/nf_reject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void nf_send_reset(struct sk_buff *oldskb, int hook)
9898

9999
nf_ct_attach(nskb, oldskb);
100100

101-
#ifdef CONFIG_BRIDGE_NETFILTER
101+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
102102
/* If we use ip_local_out for bridged traffic, the MAC source on
103103
* the RST will be ours, instead of the destination's. This confuses
104104
* some routers/firewalls, and they drop the packet. So we need to

include/net/netfilter/ipv6/nf_reject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static void nf_send_reset6(struct net *net, struct sk_buff *oldskb, int hook)
147147

148148
nf_ct_attach(nskb, oldskb);
149149

150-
#ifdef CONFIG_BRIDGE_NETFILTER
150+
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
151151
/* If we use ip6_local_out for bridged traffic, the MAC source on
152152
* the RST will be ours, instead of the destination's. This confuses
153153
* some routers/firewalls, and they drop the packet. So we need to

include/net/netfilter/nf_nat.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ struct nf_conn_nat {
3232
struct hlist_node bysource;
3333
struct nf_conn *ct;
3434
union nf_conntrack_nat_help help;
35-
#if defined(CONFIG_IP_NF_TARGET_MASQUERADE) || \
36-
defined(CONFIG_IP_NF_TARGET_MASQUERADE_MODULE) || \
37-
defined(CONFIG_IP6_NF_TARGET_MASQUERADE) || \
38-
defined(CONFIG_IP6_NF_TARGET_MASQUERADE_MODULE)
35+
#if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV4) || \
36+
IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV6)
3937
int masq_index;
4038
#endif
4139
};
@@ -68,8 +66,8 @@ static inline bool nf_nat_oif_changed(unsigned int hooknum,
6866
struct nf_conn_nat *nat,
6967
const struct net_device *out)
7068
{
71-
#if IS_ENABLED(CONFIG_IP_NF_TARGET_MASQUERADE) || \
72-
IS_ENABLED(CONFIG_IP6_NF_TARGET_MASQUERADE)
69+
#if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV4) || \
70+
IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV6)
7371
return nat->masq_index && hooknum == NF_INET_POST_ROUTING &&
7472
CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL &&
7573
nat->masq_index != out->ifindex;

include/net/netfilter/nf_tables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ void nft_unregister_set(struct nft_set_ops *ops);
241241
* @dtype: data type (verdict or numeric type defined by userspace)
242242
* @size: maximum set size
243243
* @nelems: number of elements
244+
* @policy: set parameterization (see enum nft_set_policies)
244245
* @ops: set ops
245246
* @flags: set flags
246247
* @klen: key length
@@ -255,6 +256,7 @@ struct nft_set {
255256
u32 dtype;
256257
u32 size;
257258
u32 nelems;
259+
u16 policy;
258260
/* runtime data below here */
259261
const struct nft_set_ops *ops ____cacheline_aligned;
260262
u16 flags;

include/uapi/linux/ip_vs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ enum {
384384
IPVS_DEST_ATTR_PERSIST_CONNS, /* persistent connections */
385385

386386
IPVS_DEST_ATTR_STATS, /* nested attribute for dest stats */
387+
388+
IPVS_DEST_ATTR_ADDR_FAMILY, /* Address family of address */
389+
387390
__IPVS_DEST_ATTR_MAX,
388391
};
389392

0 commit comments

Comments
 (0)