Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Browse files Browse the repository at this point in the history
Pablo Neira Ayuso says:

====================
Netfilter updates for net-next

The following patchset contains Netfilter updates for your net-next tree:

1) Support for matching on ipsec policy already set in the route, from
   Florian Westphal.

2) Split set destruction into deactivate and destroy phase to make it
   fit better into the transaction infrastructure, also from Florian.
   This includes a patch to warn on imbalance when setting the new
   activate and deactivate interfaces.

3) Release transaction list from the workqueue to remove expensive
   synchronize_rcu() from configuration plane path. This speeds up
   configuration plane quite a bit. From Florian Westphal.

4) Add new xfrm/ipsec extension, this new extension allows you to match
   for ipsec tunnel keys such as source and destination address, spi and
   reqid. From Máté Eckl and Florian Westphal.

5) Add secmark support, this includes connsecmark too, patches
   from Christian Gottsche.

6) Allow to specify remaining bytes in xt_quota, from Chenbo Feng.
   One follow up patch to calm a clang warning for this one, from
   Nathan Chancellor.

7) Flush conntrack entries based on layer 3 family, from Kristian Evensen.

8) New revision for cgroups2 to shrink the path field.

9) Get rid of obsolete need_conntrack(), as a result from recent
   demodularization works.

10) Use WARN_ON instead of BUG_ON, from Florian Westphal.

11) Unused exported symbol in nf_nat_ipv4_fn(), from Florian.

12) Remove superfluous check for timeout netlink parser and dump
    functions in layer 4 conntrack helpers.

13) Unnecessary redundant rcu read side locks in NAT redirect,
    from Taehee Yoo.

14) Pass nf_hook_state structure to error handlers, patch from
    Florian Westphal.

15) Remove ->new() interface from layer 4 protocol trackers. Place
    them in the ->packet() interface. From Florian.

16) Place conntrack ->error() handling in the ->packet() interface.
    Patches from Florian Westphal.

17) Remove unused parameter in the pernet initialization path,
    also from Florian.

18) Remove additional parameter to specify layer 3 protocol when
    looking up for protocol tracker. From Florian.

19) Shrink array of layer 4 protocol trackers, from Florian.

20) Check for linear skb only once from the ALG NAT mangling
    codebase, from Taehee Yoo.

21) Use rhashtable_walk_enter() instead of deprecated
    rhashtable_walk_init(), also from Taehee.

22) No need to flush all conntracks when only one single address
    is gone, from Tan Hu.

23) Remove redundant check for NAT flags in flowtable code, from
    Taehee Yoo.

24) Use rhashtable_lookup() instead of rhashtable_lookup_fast()
    from netfilter codebase, since rcu read lock side is already
    assumed in this path.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Oct 9, 2018
2 parents 68049a5 + ffa0a9a commit 9000a45
Show file tree
Hide file tree
Showing 53 changed files with 1,555 additions and 1,054 deletions.
3 changes: 0 additions & 3 deletions include/linux/netfilter/nf_conntrack_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ struct ip_conntrack_stat {
unsigned int search_restart;
};

/* call to create an explicit dependency on nf_conntrack. */
void need_conntrack(void);

#endif /* _NF_CONNTRACK_COMMON_H */
13 changes: 5 additions & 8 deletions include/net/netfilter/ipv4/nf_conntrack_ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@
#ifndef _NF_CONNTRACK_IPV4_H
#define _NF_CONNTRACK_IPV4_H

extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp;
#ifdef CONFIG_NF_CT_PROTO_DCCP
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp;
#endif
#ifdef CONFIG_NF_CT_PROTO_SCTP
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp;
#endif
#ifdef CONFIG_NF_CT_PROTO_UDPLITE
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite;
#endif

int nf_conntrack_ipv4_compat_init(void);
void nf_conntrack_ipv4_compat_fini(void);

#endif /*_NF_CONNTRACK_IPV4_H*/
13 changes: 0 additions & 13 deletions include/net/netfilter/ipv6/nf_conntrack_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@
#ifndef _NF_CONNTRACK_IPV6_H
#define _NF_CONNTRACK_IPV6_H

extern const struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6;

extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6;
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6;
#ifdef CONFIG_NF_CT_PROTO_DCCP
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6;
#endif
#ifdef CONFIG_NF_CT_PROTO_SCTP
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6;
#endif
#ifdef CONFIG_NF_CT_PROTO_UDPLITE
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6;
#endif

#include <linux/sysctl.h>
extern struct ctl_table nf_ct_ipv6_sysctl_table[];
Expand Down
3 changes: 1 addition & 2 deletions include/net/netfilter/nf_conntrack_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
/* This header is used to share core functionality between the
standalone connection tracking module, and the compatibility layer's use
of connection tracking. */
unsigned int nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
struct sk_buff *skb);
unsigned int nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state);

int nf_conntrack_init_net(struct net *net);
void nf_conntrack_cleanup_net(struct net *net);
Expand Down
36 changes: 16 additions & 20 deletions include/net/netfilter/nf_conntrack_l4proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
struct seq_file;

struct nf_conntrack_l4proto {
/* L3 Protocol number. */
u_int16_t l3proto;

/* L4 Protocol number. */
u_int8_t l4proto;

Expand All @@ -43,22 +40,14 @@ struct nf_conntrack_l4proto {

/* Returns verdict for packet, or -1 for invalid. */
int (*packet)(struct nf_conn *ct,
const struct sk_buff *skb,
struct sk_buff *skb,
unsigned int dataoff,
enum ip_conntrack_info ctinfo);

/* Called when a new connection for this protocol found;
* returns TRUE if it's OK. If so, packet() called next. */
bool (*new)(struct nf_conn *ct, const struct sk_buff *skb,
unsigned int dataoff);
enum ip_conntrack_info ctinfo,
const struct nf_hook_state *state);

/* Called when a conntrack entry is destroyed */
void (*destroy)(struct nf_conn *ct);

int (*error)(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
unsigned int dataoff,
u_int8_t pf, unsigned int hooknum);

/* called by gc worker if table is full */
bool (*can_early_drop)(const struct nf_conn *ct);

Expand Down Expand Up @@ -92,7 +81,7 @@ struct nf_conntrack_l4proto {
#endif
unsigned int *net_id;
/* Init l4proto pernet data */
int (*init_net)(struct net *net, u_int16_t proto);
int (*init_net)(struct net *net);

/* Return the per-net protocol part. */
struct nf_proto_net *(*get_net_proto)(struct net *net);
Expand All @@ -101,16 +90,23 @@ struct nf_conntrack_l4proto {
struct module *me;
};

int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
struct sk_buff *skb,
unsigned int dataoff,
const struct nf_hook_state *state);

int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
struct sk_buff *skb,
unsigned int dataoff,
const struct nf_hook_state *state);
/* Existing built-in generic protocol */
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;

#define MAX_NF_CT_PROTO 256
#define MAX_NF_CT_PROTO IPPROTO_UDPLITE

const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u_int16_t l3proto,
u_int8_t l4proto);
const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u8 l4proto);

const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u_int16_t l3proto,
u_int8_t l4proto);
const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u8 l4proto);
void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p);

/* Protocol pernet registration. */
Expand Down
9 changes: 8 additions & 1 deletion include/net/netfilter/nf_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
struct nft_set_binding *binding);
void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
struct nft_set_binding *binding);
void nf_tables_rebind_set(const struct nft_ctx *ctx, struct nft_set *set,
struct nft_set_binding *binding);
void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);

/**
* enum nft_set_extensions - set extension type IDs
Expand Down Expand Up @@ -724,7 +727,9 @@ struct nft_expr_type {
* @eval: Expression evaluation function
* @size: full expression size, including private data size
* @init: initialization function
* @destroy: destruction function
* @activate: activate expression in the next generation
* @deactivate: deactivate expression in next generation
* @destroy: destruction function, called after synchronize_rcu
* @dump: function to dump parameters
* @type: expression type
* @validate: validate expression, called during loop detection
Expand Down Expand Up @@ -1293,12 +1298,14 @@ static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext)
*
* @list: used internally
* @msg_type: message type
* @put_net: ctx->net needs to be put
* @ctx: transaction context
* @data: internal information related to the transaction
*/
struct nft_trans {
struct list_head list;
int msg_type;
bool put_net;
struct nft_ctx ctx;
char data[0];
};
Expand Down
4 changes: 4 additions & 0 deletions include/net/netfilter/nf_tables_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extern struct nft_expr_type nft_meta_type;
extern struct nft_expr_type nft_rt_type;
extern struct nft_expr_type nft_exthdr_type;

#ifdef CONFIG_NETWORK_SECMARK
extern struct nft_object_type nft_secmark_obj_type;
#endif

int nf_tables_core_module_init(void);
void nf_tables_core_module_exit(void);

Expand Down
49 changes: 48 additions & 1 deletion include/uapi/linux/netfilter/nf_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,12 +826,14 @@ enum nft_meta_keys {
* @NFT_RT_NEXTHOP4: routing nexthop for IPv4
* @NFT_RT_NEXTHOP6: routing nexthop for IPv6
* @NFT_RT_TCPMSS: fetch current path tcp mss
* @NFT_RT_XFRM: boolean, skb->dst->xfrm != NULL
*/
enum nft_rt_keys {
NFT_RT_CLASSID,
NFT_RT_NEXTHOP4,
NFT_RT_NEXTHOP6,
NFT_RT_TCPMSS,
NFT_RT_XFRM,
__NFT_RT_MAX
};
#define NFT_RT_MAX (__NFT_RT_MAX - 1)
Expand Down Expand Up @@ -1174,6 +1176,21 @@ enum nft_quota_attributes {
};
#define NFTA_QUOTA_MAX (__NFTA_QUOTA_MAX - 1)

/**
* enum nft_secmark_attributes - nf_tables secmark object netlink attributes
*
* @NFTA_SECMARK_CTX: security context (NLA_STRING)
*/
enum nft_secmark_attributes {
NFTA_SECMARK_UNSPEC,
NFTA_SECMARK_CTX,
__NFTA_SECMARK_MAX,
};
#define NFTA_SECMARK_MAX (__NFTA_SECMARK_MAX - 1)

/* Max security context length */
#define NFT_SECMARK_CTX_MAXLEN 256

/**
* enum nft_reject_types - nf_tables reject expression reject types
*
Expand Down Expand Up @@ -1430,7 +1447,8 @@ enum nft_ct_timeout_timeout_attributes {
#define NFT_OBJECT_CONNLIMIT 5
#define NFT_OBJECT_TUNNEL 6
#define NFT_OBJECT_CT_TIMEOUT 7
#define __NFT_OBJECT_MAX 8
#define NFT_OBJECT_SECMARK 8
#define __NFT_OBJECT_MAX 9
#define NFT_OBJECT_MAX (__NFT_OBJECT_MAX - 1)

/**
Expand Down Expand Up @@ -1512,6 +1530,35 @@ enum nft_devices_attributes {
};
#define NFTA_DEVICE_MAX (__NFTA_DEVICE_MAX - 1)

/*
* enum nft_xfrm_attributes - nf_tables xfrm expr netlink attributes
*
* @NFTA_XFRM_DREG: destination register (NLA_U32)
* @NFTA_XFRM_KEY: enum nft_xfrm_keys (NLA_U32)
* @NFTA_XFRM_DIR: direction (NLA_U8)
* @NFTA_XFRM_SPNUM: index in secpath array (NLA_U32)
*/
enum nft_xfrm_attributes {
NFTA_XFRM_UNSPEC,
NFTA_XFRM_DREG,
NFTA_XFRM_KEY,
NFTA_XFRM_DIR,
NFTA_XFRM_SPNUM,
__NFTA_XFRM_MAX
};
#define NFTA_XFRM_MAX (__NFTA_XFRM_MAX - 1)

enum nft_xfrm_keys {
NFT_XFRM_KEY_UNSPEC,
NFT_XFRM_KEY_DADDR_IP4,
NFT_XFRM_KEY_DADDR_IP6,
NFT_XFRM_KEY_SADDR_IP4,
NFT_XFRM_KEY_SADDR_IP6,
NFT_XFRM_KEY_REQID,
NFT_XFRM_KEY_SPI,
__NFT_XFRM_KEY_MAX,
};
#define NFT_XFRM_KEY_MAX (__NFT_XFRM_KEY_MAX - 1)

/**
* enum nft_trace_attributes - nf_tables trace netlink attributes
Expand Down
16 changes: 16 additions & 0 deletions include/uapi/linux/netfilter/xt_cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ struct xt_cgroup_info_v1 {
void *priv __attribute__((aligned(8)));
};

#define XT_CGROUP_PATH_MAX 512

struct xt_cgroup_info_v2 {
__u8 has_path;
__u8 has_classid;
__u8 invert_path;
__u8 invert_classid;
union {
char path[XT_CGROUP_PATH_MAX];
__u32 classid;
};

/* kernel internal data */
void *priv __attribute__((aligned(8)));
};

#endif /* _UAPI_XT_CGROUP_H */
8 changes: 5 additions & 3 deletions include/uapi/linux/netfilter/xt_quota.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ struct xt_quota_info {
__u32 flags;
__u32 pad;
__aligned_u64 quota;

/* Used internally by the kernel */
struct xt_quota_priv *master;
#ifdef __KERNEL__
atomic64_t counter;
#else
__aligned_u64 remain;
#endif
};

#endif /* _XT_QUOTA_H */
1 change: 0 additions & 1 deletion net/ipv4/netfilter/nf_nat_l3proto_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ nf_nat_ipv4_fn(void *priv, struct sk_buff *skb,

return nf_nat_inet_fn(priv, skb, state);
}
EXPORT_SYMBOL_GPL(nf_nat_ipv4_fn);

static unsigned int
nf_nat_ipv4_in(void *priv, struct sk_buff *skb,
Expand Down
22 changes: 19 additions & 3 deletions net/ipv4/netfilter/nf_nat_masquerade_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,26 @@ static int masq_device_event(struct notifier_block *this,
return NOTIFY_DONE;
}

static int inet_cmp(struct nf_conn *ct, void *ptr)
{
struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
struct net_device *dev = ifa->ifa_dev->dev;
struct nf_conntrack_tuple *tuple;

if (!device_cmp(ct, (void *)(long)dev->ifindex))
return 0;

tuple = &ct->tuplehash[IP_CT_DIR_REPLY].tuple;

return ifa->ifa_address == tuple->dst.u3.ip;
}

static int masq_inet_event(struct notifier_block *this,
unsigned long event,
void *ptr)
{
struct in_device *idev = ((struct in_ifaddr *)ptr)->ifa_dev;
struct netdev_notifier_info info;
struct net *net = dev_net(idev->dev);

/* The masq_dev_notifier will catch the case of the device going
* down. So if the inetdev is dead and being destroyed we have
Expand All @@ -119,8 +133,10 @@ static int masq_inet_event(struct notifier_block *this,
if (idev->dead)
return NOTIFY_DONE;

netdev_notifier_info_init(&info, idev->dev);
return masq_device_event(this, event, &info);
if (event == NETDEV_DOWN)
nf_ct_iterate_cleanup_net(net, inet_cmp, ptr, 0, 0);

return NOTIFY_DONE;
}

static struct notifier_block masq_dev_notifier = {
Expand Down
5 changes: 4 additions & 1 deletion net/ipv6/netfilter/ip6t_ipv6header.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ ipv6header_mt6(const struct sk_buff *skb, struct xt_action_param *par)
}

hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
BUG_ON(hp == NULL);
if (!hp) {
par->hotdrop = true;
return false;
}

/* Calculate the header length */
if (nexthdr == NEXTHDR_FRAGMENT)
Expand Down
10 changes: 8 additions & 2 deletions net/ipv6/netfilter/ip6t_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par)
sizeof(_addr),
&_addr);

BUG_ON(ap == NULL);
if (ap == NULL) {
par->hotdrop = true;
return false;
}

if (ipv6_addr_equal(ap, &rtinfo->addrs[i])) {
pr_debug("i=%d temp=%d;\n", i, temp);
Expand Down Expand Up @@ -166,7 +169,10 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par)
+ temp * sizeof(_addr),
sizeof(_addr),
&_addr);
BUG_ON(ap == NULL);
if (ap == NULL) {
par->hotdrop = true;
return false;
}

if (!ipv6_addr_equal(ap, &rtinfo->addrs[temp]))
break;
Expand Down
Loading

0 comments on commit 9000a45

Please sign in to comment.