Commit 99638e9d authored by David S. Miller's avatar David S. Miller

Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next

Pablo Neira Ayuso says:

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

The following patchset contains Netfilter updates for net-next:

1) Wildcard support for the net,iface set from Kristian Evensen.

2) Offload support for matching on the input interface.

3) Simplify matching on vlan header fields.

4) Add nft_payload_rebuild_vlan_hdr() function to rebuild the vlan
   header from the vlan sk_buff metadata.

5) Pass extack to nft_flow_cls_offload_setup().

6) Add C-VLAN matching support.

7) Use time64_t in xt_time to fix y2038 overflow, from Arnd Bergmann.

8) Use time_t in nft_meta to fix y2038 overflow, also from Arnd.

9) Add flow_action_entry_next() helper function to flowtable offload
   infrastructure.

10) Add IPv6 support to the flowtable offload infrastructure.

11) Support for input interface matching from postrouting,
    from Phil Sutter.

12) Missing check for ndo callback in flowtable offload, from wenxu.

13) Remove conntrack parameter from flow_offload_fill_dir(), from wenxu.

14) Do not pass flow_rule object for rule removal, cookie is sufficient
    to achieve this.

15) Release flow_rule object in case of error from the offload commit
    path.

16) Undo offload ruleset updates if transaction fails.

17) Check for error when binding flowtable callbacks, from wenxu.

18) Always unbind flowtable callbacks when unregistering hooks.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 19b7e21c ff4bf2f4
...@@ -163,9 +163,12 @@ void nf_flow_table_offload_flush(struct nf_flowtable *flowtable); ...@@ -163,9 +163,12 @@ void nf_flow_table_offload_flush(struct nf_flowtable *flowtable);
int nf_flow_table_offload_setup(struct nf_flowtable *flowtable, int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
struct net_device *dev, struct net_device *dev,
enum flow_block_command cmd); enum flow_block_command cmd);
int nf_flow_rule_route(struct net *net, const struct flow_offload *flow, int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct nf_flow_rule *flow_rule); struct nf_flow_rule *flow_rule);
int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir,
struct nf_flow_rule *flow_rule);
int nf_flow_table_offload_init(void); int nf_flow_table_offload_init(void);
void nf_flow_table_offload_exit(void); void nf_flow_table_offload_exit(void);
......
...@@ -45,6 +45,7 @@ struct nft_flow_key { ...@@ -45,6 +45,7 @@ struct nft_flow_key {
struct flow_dissector_key_ip ip; struct flow_dissector_key_ip ip;
struct flow_dissector_key_vlan vlan; struct flow_dissector_key_vlan vlan;
struct flow_dissector_key_eth_addrs eth_addrs; struct flow_dissector_key_eth_addrs eth_addrs;
struct flow_dissector_key_meta meta;
} __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */ } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
struct nft_flow_match { struct nft_flow_match {
......
...@@ -205,6 +205,8 @@ enum ipset_cadt_flags { ...@@ -205,6 +205,8 @@ enum ipset_cadt_flags {
IPSET_FLAG_WITH_FORCEADD = (1 << IPSET_FLAG_BIT_WITH_FORCEADD), IPSET_FLAG_WITH_FORCEADD = (1 << IPSET_FLAG_BIT_WITH_FORCEADD),
IPSET_FLAG_BIT_WITH_SKBINFO = 6, IPSET_FLAG_BIT_WITH_SKBINFO = 6,
IPSET_FLAG_WITH_SKBINFO = (1 << IPSET_FLAG_BIT_WITH_SKBINFO), IPSET_FLAG_WITH_SKBINFO = (1 << IPSET_FLAG_BIT_WITH_SKBINFO),
IPSET_FLAG_BIT_IFACE_WILDCARD = 7,
IPSET_FLAG_IFACE_WILDCARD = (1 << IPSET_FLAG_BIT_IFACE_WILDCARD),
IPSET_FLAG_CADT_MAX = 15, IPSET_FLAG_CADT_MAX = 15,
}; };
......
...@@ -422,7 +422,7 @@ int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -422,7 +422,7 @@ int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb)
int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb) int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb)
{ {
struct net_device *dev = skb_dst(skb)->dev; struct net_device *dev = skb_dst(skb)->dev, *indev = skb->dev;
IP_UPD_PO_STATS(net, IPSTATS_MIB_OUT, skb->len); IP_UPD_PO_STATS(net, IPSTATS_MIB_OUT, skb->len);
...@@ -430,7 +430,7 @@ int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -430,7 +430,7 @@ int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb)
skb->protocol = htons(ETH_P_IP); skb->protocol = htons(ETH_P_IP);
return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING, return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING,
net, sk, skb, NULL, dev, net, sk, skb, indev, dev,
ip_finish_output, ip_finish_output,
!(IPCB(skb)->flags & IPSKB_REROUTED)); !(IPCB(skb)->flags & IPSKB_REROUTED));
} }
......
...@@ -10,7 +10,7 @@ static struct nf_flowtable_type flowtable_ipv4 = { ...@@ -10,7 +10,7 @@ static struct nf_flowtable_type flowtable_ipv4 = {
.family = NFPROTO_IPV4, .family = NFPROTO_IPV4,
.init = nf_flow_table_init, .init = nf_flow_table_init,
.setup = nf_flow_table_offload_setup, .setup = nf_flow_table_offload_setup,
.action = nf_flow_rule_route, .action = nf_flow_rule_route_ipv4,
.free = nf_flow_table_free, .free = nf_flow_table_free,
.hook = nf_flow_offload_ip_hook, .hook = nf_flow_offload_ip_hook,
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
...@@ -92,7 +92,7 @@ static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -92,7 +92,7 @@ static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb) int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
{ {
return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING, return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING,
net, sk, skb, NULL, skb_dst(skb)->dev, net, sk, skb, skb->dev, skb_dst(skb)->dev,
__xfrm4_output, __xfrm4_output,
!(IPCB(skb)->flags & IPSKB_REROUTED)); !(IPCB(skb)->flags & IPSKB_REROUTED));
} }
......
...@@ -160,7 +160,7 @@ static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *s ...@@ -160,7 +160,7 @@ static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *s
int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb) int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
{ {
struct net_device *dev = skb_dst(skb)->dev; struct net_device *dev = skb_dst(skb)->dev, *indev = skb->dev;
struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb)); struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
skb->protocol = htons(ETH_P_IPV6); skb->protocol = htons(ETH_P_IPV6);
...@@ -173,7 +173,7 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -173,7 +173,7 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
} }
return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING,
net, sk, skb, NULL, dev, net, sk, skb, indev, dev,
ip6_finish_output, ip6_finish_output,
!(IP6CB(skb)->flags & IP6SKB_REROUTED)); !(IP6CB(skb)->flags & IP6SKB_REROUTED));
} }
......
...@@ -11,7 +11,7 @@ static struct nf_flowtable_type flowtable_ipv6 = { ...@@ -11,7 +11,7 @@ static struct nf_flowtable_type flowtable_ipv6 = {
.family = NFPROTO_IPV6, .family = NFPROTO_IPV6,
.init = nf_flow_table_init, .init = nf_flow_table_init,
.setup = nf_flow_table_offload_setup, .setup = nf_flow_table_offload_setup,
.action = nf_flow_rule_route, .action = nf_flow_rule_route_ipv6,
.free = nf_flow_table_free, .free = nf_flow_table_free,
.hook = nf_flow_offload_ipv6_hook, .hook = nf_flow_offload_ipv6_hook,
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
...@@ -187,7 +187,7 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -187,7 +187,7 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb) int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
{ {
return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING,
net, sk, skb, NULL, skb_dst(skb)->dev, net, sk, skb, skb->dev, skb_dst(skb)->dev,
__xfrm6_output, __xfrm6_output,
!(IP6CB(skb)->flags & IP6SKB_REROUTED)); !(IP6CB(skb)->flags & IP6SKB_REROUTED));
} }
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
/* 3 Counters support added */ /* 3 Counters support added */
/* 4 Comments support added */ /* 4 Comments support added */
/* 5 Forceadd support added */ /* 5 Forceadd support added */
#define IPSET_TYPE_REV_MAX 6 /* skbinfo support added */ /* 6 skbinfo support added */
#define IPSET_TYPE_REV_MAX 7 /* interface wildcard support added */
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@netfilter.org>"); MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@netfilter.org>");
...@@ -57,6 +58,7 @@ struct hash_netiface4_elem { ...@@ -57,6 +58,7 @@ struct hash_netiface4_elem {
u8 cidr; u8 cidr;
u8 nomatch; u8 nomatch;
u8 elem; u8 elem;
u8 wildcard;
char iface[IFNAMSIZ]; char iface[IFNAMSIZ];
}; };
...@@ -71,7 +73,9 @@ hash_netiface4_data_equal(const struct hash_netiface4_elem *ip1, ...@@ -71,7 +73,9 @@ hash_netiface4_data_equal(const struct hash_netiface4_elem *ip1,
ip1->cidr == ip2->cidr && ip1->cidr == ip2->cidr &&
(++*multi) && (++*multi) &&
ip1->physdev == ip2->physdev && ip1->physdev == ip2->physdev &&
strcmp(ip1->iface, ip2->iface) == 0; (ip1->wildcard ?
strncmp(ip1->iface, ip2->iface, strlen(ip1->iface)) == 0 :
strcmp(ip1->iface, ip2->iface) == 0);
} }
static int static int
...@@ -103,7 +107,8 @@ static bool ...@@ -103,7 +107,8 @@ static bool
hash_netiface4_data_list(struct sk_buff *skb, hash_netiface4_data_list(struct sk_buff *skb,
const struct hash_netiface4_elem *data) const struct hash_netiface4_elem *data)
{ {
u32 flags = data->physdev ? IPSET_FLAG_PHYSDEV : 0; u32 flags = (data->physdev ? IPSET_FLAG_PHYSDEV : 0) |
(data->wildcard ? IPSET_FLAG_IFACE_WILDCARD : 0);
if (data->nomatch) if (data->nomatch)
flags |= IPSET_FLAG_NOMATCH; flags |= IPSET_FLAG_NOMATCH;
...@@ -229,6 +234,8 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[], ...@@ -229,6 +234,8 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[],
e.physdev = 1; e.physdev = 1;
if (cadt_flags & IPSET_FLAG_NOMATCH) if (cadt_flags & IPSET_FLAG_NOMATCH)
flags |= (IPSET_FLAG_NOMATCH << 16); flags |= (IPSET_FLAG_NOMATCH << 16);
if (cadt_flags & IPSET_FLAG_IFACE_WILDCARD)
e.wildcard = 1;
} }
if (adt == IPSET_TEST || !tb[IPSET_ATTR_IP_TO]) { if (adt == IPSET_TEST || !tb[IPSET_ATTR_IP_TO]) {
e.ip = htonl(ip & ip_set_hostmask(e.cidr)); e.ip = htonl(ip & ip_set_hostmask(e.cidr));
...@@ -280,6 +287,7 @@ struct hash_netiface6_elem { ...@@ -280,6 +287,7 @@ struct hash_netiface6_elem {
u8 cidr; u8 cidr;
u8 nomatch; u8 nomatch;
u8 elem; u8 elem;
u8 wildcard;
char iface[IFNAMSIZ]; char iface[IFNAMSIZ];
}; };
...@@ -294,7 +302,9 @@ hash_netiface6_data_equal(const struct hash_netiface6_elem *ip1, ...@@ -294,7 +302,9 @@ hash_netiface6_data_equal(const struct hash_netiface6_elem *ip1,
ip1->cidr == ip2->cidr && ip1->cidr == ip2->cidr &&
(++*multi) && (++*multi) &&
ip1->physdev == ip2->physdev && ip1->physdev == ip2->physdev &&
strcmp(ip1->iface, ip2->iface) == 0; (ip1->wildcard ?
strncmp(ip1->iface, ip2->iface, strlen(ip1->iface)) == 0 :
strcmp(ip1->iface, ip2->iface) == 0);
} }
static int static int
...@@ -326,7 +336,8 @@ static bool ...@@ -326,7 +336,8 @@ static bool
hash_netiface6_data_list(struct sk_buff *skb, hash_netiface6_data_list(struct sk_buff *skb,
const struct hash_netiface6_elem *data) const struct hash_netiface6_elem *data)
{ {
u32 flags = data->physdev ? IPSET_FLAG_PHYSDEV : 0; u32 flags = (data->physdev ? IPSET_FLAG_PHYSDEV : 0) |
(data->wildcard ? IPSET_FLAG_IFACE_WILDCARD : 0);
if (data->nomatch) if (data->nomatch)
flags |= IPSET_FLAG_NOMATCH; flags |= IPSET_FLAG_NOMATCH;
...@@ -440,6 +451,8 @@ hash_netiface6_uadt(struct ip_set *set, struct nlattr *tb[], ...@@ -440,6 +451,8 @@ hash_netiface6_uadt(struct ip_set *set, struct nlattr *tb[],
e.physdev = 1; e.physdev = 1;
if (cadt_flags & IPSET_FLAG_NOMATCH) if (cadt_flags & IPSET_FLAG_NOMATCH)
flags |= (IPSET_FLAG_NOMATCH << 16); flags |= (IPSET_FLAG_NOMATCH << 16);
if (cadt_flags & IPSET_FLAG_IFACE_WILDCARD)
e.wildcard = 1;
} }
ret = adtfn(set, &e, &ext, &ext, flags); ret = adtfn(set, &e, &ext, &ext, flags);
......
...@@ -18,11 +18,11 @@ static DEFINE_MUTEX(flowtable_lock); ...@@ -18,11 +18,11 @@ static DEFINE_MUTEX(flowtable_lock);
static LIST_HEAD(flowtables); static LIST_HEAD(flowtables);
static void static void
flow_offload_fill_dir(struct flow_offload *flow, struct nf_conn *ct, flow_offload_fill_dir(struct flow_offload *flow,
enum flow_offload_tuple_dir dir) enum flow_offload_tuple_dir dir)
{ {
struct flow_offload_tuple *ft = &flow->tuplehash[dir].tuple; struct flow_offload_tuple *ft = &flow->tuplehash[dir].tuple;
struct nf_conntrack_tuple *ctt = &ct->tuplehash[dir].tuple; struct nf_conntrack_tuple *ctt = &flow->ct->tuplehash[dir].tuple;
ft->dir = dir; ft->dir = dir;
...@@ -57,8 +57,8 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct) ...@@ -57,8 +57,8 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct)
flow->ct = ct; flow->ct = ct;
flow_offload_fill_dir(flow, ct, FLOW_OFFLOAD_DIR_ORIGINAL); flow_offload_fill_dir(flow, FLOW_OFFLOAD_DIR_ORIGINAL);
flow_offload_fill_dir(flow, ct, FLOW_OFFLOAD_DIR_REPLY); flow_offload_fill_dir(flow, FLOW_OFFLOAD_DIR_REPLY);
if (ct->status & IPS_SRC_NAT) if (ct->status & IPS_SRC_NAT)
flow->flags |= FLOW_OFFLOAD_SNAT; flow->flags |= FLOW_OFFLOAD_SNAT;
......
...@@ -21,11 +21,34 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb, ...@@ -21,11 +21,34 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,
return NF_ACCEPT; return NF_ACCEPT;
} }
static int nf_flow_rule_route_inet(struct net *net,
const struct flow_offload *flow,
enum flow_offload_tuple_dir dir,
struct nf_flow_rule *flow_rule)
{
const struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;
int err;
switch (flow_tuple->l3proto) {
case NFPROTO_IPV4:
err = nf_flow_rule_route_ipv4(net, flow, dir, flow_rule);
break;
case NFPROTO_IPV6:
err = nf_flow_rule_route_ipv6(net, flow, dir, flow_rule);
break;
default:
err = -1;
break;
}
return err;
}
static struct nf_flowtable_type flowtable_inet = { static struct nf_flowtable_type flowtable_inet = {
.family = NFPROTO_INET, .family = NFPROTO_INET,
.init = nf_flow_table_init, .init = nf_flow_table_init,
.setup = nf_flow_table_offload_setup, .setup = nf_flow_table_offload_setup,
.action = nf_flow_rule_route, .action = nf_flow_rule_route_inet,
.free = nf_flow_table_free, .free = nf_flow_table_free,
.hook = nf_flow_offload_inet_hook, .hook = nf_flow_offload_inet_hook,
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
...@@ -112,13 +112,22 @@ static void flow_offload_mangle(struct flow_action_entry *entry, ...@@ -112,13 +112,22 @@ static void flow_offload_mangle(struct flow_action_entry *entry,
memcpy(&entry->mangle.val, value, sizeof(u32)); memcpy(&entry->mangle.val, value, sizeof(u32));
} }
static inline struct flow_action_entry *
flow_action_entry_next(struct nf_flow_rule *flow_rule)
{
int i = flow_rule->rule->action.num_entries++;
return &flow_rule->rule->action.entries[i];
}
static int flow_offload_eth_src(struct net *net, static int flow_offload_eth_src(struct net *net,
const struct flow_offload *flow, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct flow_action_entry *entry0, struct nf_flow_rule *flow_rule)
struct flow_action_entry *entry1)
{ {
const struct flow_offload_tuple *tuple = &flow->tuplehash[!dir].tuple; const struct flow_offload_tuple *tuple = &flow->tuplehash[!dir].tuple;
struct flow_action_entry *entry0 = flow_action_entry_next(flow_rule);
struct flow_action_entry *entry1 = flow_action_entry_next(flow_rule);
struct net_device *dev; struct net_device *dev;
u32 mask, val; u32 mask, val;
u16 val16; u16 val16;
...@@ -145,10 +154,11 @@ static int flow_offload_eth_src(struct net *net, ...@@ -145,10 +154,11 @@ static int flow_offload_eth_src(struct net *net,
static int flow_offload_eth_dst(struct net *net, static int flow_offload_eth_dst(struct net *net,
const struct flow_offload *flow, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct flow_action_entry *entry0, struct nf_flow_rule *flow_rule)
struct flow_action_entry *entry1)
{ {
const struct flow_offload_tuple *tuple = &flow->tuplehash[dir].tuple; const struct flow_offload_tuple *tuple = &flow->tuplehash[dir].tuple;
struct flow_action_entry *entry0 = flow_action_entry_next(flow_rule);
struct flow_action_entry *entry1 = flow_action_entry_next(flow_rule);
struct neighbour *n; struct neighbour *n;
u32 mask, val; u32 mask, val;
u16 val16; u16 val16;
...@@ -175,8 +185,9 @@ static int flow_offload_eth_dst(struct net *net, ...@@ -175,8 +185,9 @@ static int flow_offload_eth_dst(struct net *net,
static void flow_offload_ipv4_snat(struct net *net, static void flow_offload_ipv4_snat(struct net *net,
const struct flow_offload *flow, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct flow_action_entry *entry) struct nf_flow_rule *flow_rule)
{ {
struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
u32 mask = ~htonl(0xffffffff); u32 mask = ~htonl(0xffffffff);
__be32 addr; __be32 addr;
u32 offset; u32 offset;
...@@ -201,8 +212,9 @@ static void flow_offload_ipv4_snat(struct net *net, ...@@ -201,8 +212,9 @@ static void flow_offload_ipv4_snat(struct net *net,
static void flow_offload_ipv4_dnat(struct net *net, static void flow_offload_ipv4_dnat(struct net *net,
const struct flow_offload *flow, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct flow_action_entry *entry) struct nf_flow_rule *flow_rule)
{ {
struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
u32 mask = ~htonl(0xffffffff); u32 mask = ~htonl(0xffffffff);
__be32 addr; __be32 addr;
u32 offset; u32 offset;
...@@ -224,6 +236,71 @@ static void flow_offload_ipv4_dnat(struct net *net, ...@@ -224,6 +236,71 @@ static void flow_offload_ipv4_dnat(struct net *net,
(u8 *)&addr, (u8 *)&mask); (u8 *)&addr, (u8 *)&mask);
} }
static void flow_offload_ipv6_mangle(struct nf_flow_rule *flow_rule,
unsigned int offset,
u8 *addr, u8 *mask)
{
struct flow_action_entry *entry;
int i;
for (i = 0; i < sizeof(struct in6_addr) / sizeof(u32); i += sizeof(u32)) {
entry = flow_action_entry_next(flow_rule);
flow_offload_mangle(entry, FLOW_ACT_MANGLE_HDR_TYPE_IP6,
offset + i,
&addr[i], mask);
}
}
static void flow_offload_ipv6_snat(struct net *net,
const struct flow_offload *flow,
enum flow_offload_tuple_dir dir,
struct nf_flow_rule *flow_rule)
{
u32 mask = ~htonl(0xffffffff);
const u8 *addr;
u32 offset;
switch (dir) {
case FLOW_OFFLOAD_DIR_ORIGINAL:
addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_v6.s6_addr;
offset = offsetof(struct ipv6hdr, saddr);
break;
case FLOW_OFFLOAD_DIR_REPLY:
addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.src_v6.s6_addr;
offset = offsetof(struct ipv6hdr, daddr);
break;
default:
return;
}
flow_offload_ipv6_mangle(flow_rule, offset, (u8 *)addr, (u8 *)&mask);
}
static void flow_offload_ipv6_dnat(struct net *net,
const struct flow_offload *flow,
enum flow_offload_tuple_dir dir,
struct nf_flow_rule *flow_rule)
{
u32 mask = ~htonl(0xffffffff);
const u8 *addr;
u32 offset;
switch (dir) {
case FLOW_OFFLOAD_DIR_ORIGINAL:
addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.src_v6.s6_addr;
offset = offsetof(struct ipv6hdr, daddr);
break;
case FLOW_OFFLOAD_DIR_REPLY:
addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.dst_v6.s6_addr;
offset = offsetof(struct ipv6hdr, saddr);
break;
default:
return;
}
flow_offload_ipv6_mangle(flow_rule, offset, (u8 *)addr, (u8 *)&mask);
}
static int flow_offload_l4proto(const struct flow_offload *flow) static int flow_offload_l4proto(const struct flow_offload *flow)
{ {
u8 protonum = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.l4proto; u8 protonum = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.l4proto;
...@@ -246,8 +323,9 @@ static int flow_offload_l4proto(const struct flow_offload *flow) ...@@ -246,8 +323,9 @@ static int flow_offload_l4proto(const struct flow_offload *flow)
static void flow_offload_port_snat(struct net *net, static void flow_offload_port_snat(struct net *net,
const struct flow_offload *flow, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct flow_action_entry *entry) struct nf_flow_rule *flow_rule)
{ {
struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
u32 mask = ~htonl(0xffff0000); u32 mask = ~htonl(0xffff0000);
__be16 port; __be16 port;
u32 offset; u32 offset;
...@@ -272,8 +350,9 @@ static void flow_offload_port_snat(struct net *net, ...@@ -272,8 +350,9 @@ static void flow_offload_port_snat(struct net *net,
static void flow_offload_port_dnat(struct net *net, static void flow_offload_port_dnat(struct net *net,
const struct flow_offload *flow, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct flow_action_entry *entry) struct nf_flow_rule *flow_rule)
{ {
struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
u32 mask = ~htonl(0xffff); u32 mask = ~htonl(0xffff);
__be16 port; __be16 port;
u32 offset; u32 offset;
...@@ -297,9 +376,10 @@ static void flow_offload_port_dnat(struct net *net, ...@@ -297,9 +376,10 @@ static void flow_offload_port_dnat(struct net *net,
static void flow_offload_ipv4_checksum(struct net *net, static void flow_offload_ipv4_checksum(struct net *net,
const struct flow_offload *flow, const struct flow_offload *flow,
struct flow_action_entry *entry) struct nf_flow_rule *flow_rule)
{ {
u8 protonum = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.l4proto; u8 protonum = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.l4proto;
struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
entry->id = FLOW_ACTION_CSUM; entry->id = FLOW_ACTION_CSUM;
entry->csum_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR; entry->csum_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR;
...@@ -316,8 +396,9 @@ static void flow_offload_ipv4_checksum(struct net *net, ...@@ -316,8 +396,9 @@ static void flow_offload_ipv4_checksum(struct net *net,
static void flow_offload_redirect(const struct flow_offload *flow, static void flow_offload_redirect(const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct flow_action_entry *entry) struct nf_flow_rule *flow_rule)
{ {
struct flow_action_entry *entry = flow_action_entry_next(flow_rule);
struct rtable *rt; struct rtable *rt;
rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
...@@ -326,45 +407,56 @@ static void flow_offload_redirect(const struct flow_offload *flow, ...@@ -326,45 +407,56 @@ static void flow_offload_redirect(const struct flow_offload *flow,
dev_hold(rt->dst.dev); dev_hold(rt->dst.dev);
} }
int nf_flow_rule_route(struct net *net, const struct flow_offload *flow, int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir, enum flow_offload_tuple_dir dir,
struct nf_flow_rule *flow_rule) struct nf_flow_rule *flow_rule)
{ {
int i; if (flow_offload_eth_src(net, flow, dir, flow_rule) < 0 ||
flow_offload_eth_dst(net, flow, dir, flow_rule) < 0)
if (flow_offload_eth_src(net, flow, dir,
&flow_rule->rule->action.entries[0],
&flow_rule->rule->action.entries[1]) < 0)
return -1; return -1;
if (flow_offload_eth_dst(net, flow, dir,
&flow_rule->rule->action.entries[2],
&flow_rule->rule->action.entries[3]) < 0)
return -1;
i = 4;
if (flow->flags & FLOW_OFFLOAD_SNAT) { if (flow->flags & FLOW_OFFLOAD_SNAT) {
flow_offload_ipv4_snat(net, flow, dir, flow_offload_ipv4_snat(net, flow, dir, flow_rule);
&flow_rule->rule->action.entries[i++]); flow_offload_port_snat(net, flow, dir, flow_rule);
flow_offload_port_snat(net, flow, dir,
&flow_rule->rule->action.entries[i++]);
} }
if (flow->flags & FLOW_OFFLOAD_DNAT) { if (flow->flags & FLOW_OFFLOAD_DNAT) {
flow_offload_ipv4_dnat(net, flow, dir, flow_offload_ipv4_dnat(net, flow, dir, flow_rule);
&flow_rule->rule->action.entries[i++]); flow_offload_port_dnat(net, flow, dir, flow_rule);
flow_offload_port_dnat(net, flow, dir,
&flow_rule->rule->action.entries[i++]);
} }
if (flow->flags & FLOW_OFFLOAD_SNAT || if (flow->flags & FLOW_OFFLOAD_SNAT ||
flow->flags & FLOW_OFFLOAD_DNAT) flow->flags & FLOW_OFFLOAD_DNAT)
flow_offload_ipv4_checksum(net, flow, flow_offload_ipv4_checksum(net, flow, flow_rule);
&flow_rule->rule->action.entries[i++]);
flow_offload_redirect(flow, dir, &flow_rule->rule->action.entries[i++]); flow_offload_redirect(flow, dir, flow_rule);
return i; return 0;
} }
EXPORT_SYMBOL_GPL(nf_flow_rule_route); EXPORT_SYMBOL_GPL(nf_flow_rule_route_ipv4);
int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow,
enum flow_offload_tuple_dir dir,
struct nf_flow_rule *flow_rule)
{
if (flow_offload_eth_src(net, flow, dir, flow_rule) < 0 ||
flow_offload_eth_dst(net, flow, dir, flow_rule) < 0)
return -1;
if (flow->flags & FLOW_OFFLOAD_SNAT) {
flow_offload_ipv6_snat(net, flow, dir, flow_rule);
flow_offload_port_snat(net, flow, dir, flow_rule);
}
if (flow->flags & FLOW_OFFLOAD_DNAT) {
flow_offload_ipv6_dnat(net, flow, dir, flow_rule);
flow_offload_port_dnat(net, flow, dir, flow_rule);
}
flow_offload_redirect(flow, dir, flow_rule);
return 0;
}
EXPORT_SYMBOL_GPL(nf_flow_rule_route_ipv6);
#define NF_FLOW_RULE_ACTION_MAX 16
static struct nf_flow_rule * static struct nf_flow_rule *
nf_flow_offload_rule_alloc(struct net *net, nf_flow_offload_rule_alloc(struct net *net,
...@@ -375,13 +467,13 @@ nf_flow_offload_rule_alloc(struct net *net, ...@@ -375,13 +467,13 @@ nf_flow_offload_rule_alloc(struct net *net,
const struct flow_offload *flow = offload->flow; const struct flow_offload *flow = offload->flow;
const struct flow_offload_tuple *tuple; const struct flow_offload_tuple *tuple;
struct nf_flow_rule *flow_rule; struct nf_flow_rule *flow_rule;
int err = -ENOMEM, num_actions; int err = -ENOMEM;
flow_rule = kzalloc(sizeof(*flow_rule), GFP_KERNEL); flow_rule = kzalloc(sizeof(*flow_rule), GFP_KERNEL);
if (!flow_rule) if (!flow_rule)
goto err_flow; goto err_flow;
flow_rule->rule = flow_rule_alloc(10); flow_rule->rule = flow_rule_alloc(NF_FLOW_RULE_ACTION_MAX);
if (!flow_rule->rule) if (!flow_rule->rule)
goto err_flow_rule; goto err_flow_rule;
...@@ -394,12 +486,10 @@ nf_flow_offload_rule_alloc(struct net *net, ...@@ -394,12 +486,10 @@ nf_flow_offload_rule_alloc(struct net *net,
if (err < 0) if (err < 0)
goto err_flow_match; goto err_flow_match;
num_actions = flowtable->type->action(net, flow, dir, flow_rule); flow_rule->rule->action.num_entries = 0;
if (num_actions < 0) if (flowtable->type->action(net, flow, dir, flow_rule) < 0)
goto err_flow_match; goto err_flow_match;
flow_rule->rule->action.num_entries = num_actions;
return flow_rule; return flow_rule;
err_flow_match: err_flow_match:
...@@ -722,6 +812,9 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable, ...@@ -722,6 +812,9 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
if (!(flowtable->flags & NF_FLOWTABLE_HW_OFFLOAD)) if (!(flowtable->flags & NF_FLOWTABLE_HW_OFFLOAD))
return 0; return 0;
if (!dev->netdev_ops->ndo_setup_tc)
return -EOPNOTSUPP;
bo.net = dev_net(dev); bo.net = dev_net(dev);
bo.block = &flowtable->flow_block; bo.block = &flowtable->flow_block;
bo.command = cmd; bo.command = cmd;
......
...@@ -361,6 +361,7 @@ static struct nft_trans *nft_trans_rule_add(struct nft_ctx *ctx, int msg_type, ...@@ -361,6 +361,7 @@ static struct nft_trans *nft_trans_rule_add(struct nft_ctx *ctx, int msg_type,
static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule) static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
{ {
struct nft_flow_rule *flow;
struct nft_trans *trans; struct nft_trans *trans;
int err; int err;
...@@ -368,6 +369,16 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule) ...@@ -368,6 +369,16 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
if (trans == NULL) if (trans == NULL)
return -ENOMEM; return -ENOMEM;
if (ctx->chain->flags & NFT_CHAIN_HW_OFFLOAD) {
flow = nft_flow_rule_create(ctx->net, rule);
if (IS_ERR(flow)) {
nft_trans_destroy(trans);
return PTR_ERR(flow);
}
nft_trans_flow_rule(trans) = flow;
}
err = nf_tables_delrule_deactivate(ctx, rule); err = nf_tables_delrule_deactivate(ctx, rule);
if (err < 0) { if (err < 0) {
nft_trans_destroy(trans); nft_trans_destroy(trans);
...@@ -5964,16 +5975,22 @@ nft_flowtable_type_get(struct net *net, u8 family) ...@@ -5964,16 +5975,22 @@ nft_flowtable_type_get(struct net *net, u8 family)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
static void nft_unregister_flowtable_hook(struct net *net,
struct nft_flowtable *flowtable,
struct nft_hook *hook)
{
nf_unregister_net_hook(net, &hook->ops);
flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
FLOW_BLOCK_UNBIND);
}
static void nft_unregister_flowtable_net_hooks(struct net *net, static void nft_unregister_flowtable_net_hooks(struct net *net,
struct nft_flowtable *flowtable) struct nft_flowtable *flowtable)
{ {
struct nft_hook *hook; struct nft_hook *hook;
list_for_each_entry(hook, &flowtable->hook_list, list) { list_for_each_entry(hook, &flowtable->hook_list, list)
nf_unregister_net_hook(net, &hook->ops); nft_unregister_flowtable_hook(net, flowtable, hook);
flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
FLOW_BLOCK_UNBIND);
}
} }
static int nft_register_flowtable_net_hooks(struct net *net, static int nft_register_flowtable_net_hooks(struct net *net,
...@@ -5995,12 +6012,20 @@ static int nft_register_flowtable_net_hooks(struct net *net, ...@@ -5995,12 +6012,20 @@ static int nft_register_flowtable_net_hooks(struct net *net,
} }
} }
flowtable->data.type->setup(&flowtable->data, hook->ops.dev, err = flowtable->data.type->setup(&flowtable->data,
FLOW_BLOCK_BIND); hook->ops.dev,
err = nf_register_net_hook(net, &hook->ops); FLOW_BLOCK_BIND);
if (err < 0) if (err < 0)
goto err_unregister_net_hooks; goto err_unregister_net_hooks;
err = nf_register_net_hook(net, &hook->ops);
if (err < 0) {
flowtable->data.type->setup(&flowtable->data,
hook->ops.dev,
FLOW_BLOCK_UNBIND);
goto err_unregister_net_hooks;
}
i++; i++;
} }
...@@ -6011,9 +6036,7 @@ static int nft_register_flowtable_net_hooks(struct net *net, ...@@ -6011,9 +6036,7 @@ static int nft_register_flowtable_net_hooks(struct net *net,
if (i-- <= 0) if (i-- <= 0)
break; break;
nf_unregister_net_hook(net, &hook->ops); nft_unregister_flowtable_hook(net, flowtable, hook);
flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
FLOW_BLOCK_UNBIND);
list_del_rcu(&hook->list); list_del_rcu(&hook->list);
kfree_rcu(hook, rcu); kfree_rcu(hook, rcu);
} }
...@@ -6120,7 +6143,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, ...@@ -6120,7 +6143,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
return 0; return 0;
err5: err5:
list_for_each_entry_safe(hook, next, &flowtable->hook_list, list) { list_for_each_entry_safe(hook, next, &flowtable->hook_list, list) {
nf_unregister_net_hook(net, &hook->ops); nft_unregister_flowtable_hook(net, flowtable, hook);
list_del_rcu(&hook->list); list_del_rcu(&hook->list);
kfree_rcu(hook, rcu); kfree_rcu(hook, rcu);
} }
...@@ -6465,7 +6488,7 @@ static void nft_flowtable_event(unsigned long event, struct net_device *dev, ...@@ -6465,7 +6488,7 @@ static void nft_flowtable_event(unsigned long event, struct net_device *dev,
if (hook->ops.dev != dev) if (hook->ops.dev != dev)
continue; continue;
nf_unregister_net_hook(dev_net(dev), &hook->ops); nft_unregister_flowtable_hook(dev_net(dev), flowtable, hook);
list_del_rcu(&hook->list); list_del_rcu(&hook->list);
kfree_rcu(hook, rcu); kfree_rcu(hook, rcu);
break; break;
......
...@@ -159,9 +159,9 @@ static void nft_flow_cls_offload_setup(struct flow_cls_offload *cls_flow, ...@@ -159,9 +159,9 @@ static void nft_flow_cls_offload_setup(struct flow_cls_offload *cls_flow,
const struct nft_base_chain *basechain, const struct nft_base_chain *basechain,
const struct nft_rule *rule, const struct nft_rule *rule,
const struct nft_flow_rule *flow, const struct nft_flow_rule *flow,
struct netlink_ext_ack *extack,
enum flow_cls_command command) enum flow_cls_command command)
{ {
struct netlink_ext_ack extack;
__be16 proto = ETH_P_ALL; __be16 proto = ETH_P_ALL;
memset(cls_flow, 0, sizeof(*cls_flow)); memset(cls_flow, 0, sizeof(*cls_flow));
...@@ -170,7 +170,7 @@ static void nft_flow_cls_offload_setup(struct flow_cls_offload *cls_flow, ...@@ -170,7 +170,7 @@ static void nft_flow_cls_offload_setup(struct flow_cls_offload *cls_flow,
proto = flow->proto; proto = flow->proto;
nft_flow_offload_common_init(&cls_flow->common, proto, nft_flow_offload_common_init(&cls_flow->common, proto,
basechain->ops.priority, &extack); basechain->ops.priority, extack);
cls_flow->command = command; cls_flow->command = command;
cls_flow->cookie = (unsigned long) rule; cls_flow->cookie = (unsigned long) rule;
if (flow) if (flow)
...@@ -182,6 +182,7 @@ static int nft_flow_offload_rule(struct nft_chain *chain, ...@@ -182,6 +182,7 @@ static int nft_flow_offload_rule(struct nft_chain *chain,
struct nft_flow_rule *flow, struct nft_flow_rule *flow,
enum flow_cls_command command) enum flow_cls_command command)
{ {
struct netlink_ext_ack extack = {};
struct flow_cls_offload cls_flow; struct flow_cls_offload cls_flow;
struct nft_base_chain *basechain; struct nft_base_chain *basechain;
...@@ -189,7 +190,8 @@ static int nft_flow_offload_rule(struct nft_chain *chain, ...@@ -189,7 +190,8 @@ static int nft_flow_offload_rule(struct nft_chain *chain,
return -EOPNOTSUPP; return -EOPNOTSUPP;
basechain = nft_base_chain(chain); basechain = nft_base_chain(chain);
nft_flow_cls_offload_setup(&cls_flow, basechain, rule, flow, command); nft_flow_cls_offload_setup(&cls_flow, basechain, rule, flow, &extack,
command);
return nft_setup_cb_call(TC_SETUP_CLSFLOWER, &cls_flow, return nft_setup_cb_call(TC_SETUP_CLSFLOWER, &cls_flow,
&basechain->flow_block.cb_list); &basechain->flow_block.cb_list);
...@@ -207,13 +209,15 @@ static int nft_flow_offload_unbind(struct flow_block_offload *bo, ...@@ -207,13 +209,15 @@ static int nft_flow_offload_unbind(struct flow_block_offload *bo,
{ {
struct flow_block_cb *block_cb, *next; struct flow_block_cb *block_cb, *next;
struct flow_cls_offload cls_flow; struct flow_cls_offload cls_flow;
struct netlink_ext_ack extack;
struct nft_chain *chain; struct nft_chain *chain;
struct nft_rule *rule; struct nft_rule *rule;
chain = &basechain->chain; chain = &basechain->chain;
list_for_each_entry(rule, &chain->rules, list) { list_for_each_entry(rule, &chain->rules, list) {
memset(&extack, 0, sizeof(extack));
nft_flow_cls_offload_setup(&cls_flow, basechain, rule, NULL, nft_flow_cls_offload_setup(&cls_flow, basechain, rule, NULL,
FLOW_CLS_DESTROY); &extack, FLOW_CLS_DESTROY);
nft_setup_cb_call(TC_SETUP_CLSFLOWER, &cls_flow, &bo->cb_list); nft_setup_cb_call(TC_SETUP_CLSFLOWER, &cls_flow, &bo->cb_list);
} }
...@@ -385,6 +389,55 @@ static int nft_flow_offload_chain(struct nft_chain *chain, u8 *ppolicy, ...@@ -385,6 +389,55 @@ static int nft_flow_offload_chain(struct nft_chain *chain, u8 *ppolicy,
return nft_flow_block_chain(basechain, NULL, cmd); return nft_flow_block_chain(basechain, NULL, cmd);
} }
static void nft_flow_rule_offload_abort(struct net *net,
struct nft_trans *trans)
{
int err = 0;
list_for_each_entry_continue_reverse(trans, &net->nft.commit_list, list) {
if (trans->ctx.family != NFPROTO_NETDEV)
continue;
switch (trans->msg_type) {
case NFT_MSG_NEWCHAIN:
if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD) ||
nft_trans_chain_update(trans))
continue;
err = nft_flow_offload_chain(trans->ctx.chain, NULL,
FLOW_BLOCK_UNBIND);
break;
case NFT_MSG_DELCHAIN:
if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
continue;
err = nft_flow_offload_chain(trans->ctx.chain, NULL,
FLOW_BLOCK_BIND);
break;
case NFT_MSG_NEWRULE:
if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
continue;
err = nft_flow_offload_rule(trans->ctx.chain,
nft_trans_rule(trans),
NULL, FLOW_CLS_DESTROY);
break;
case NFT_MSG_DELRULE:
if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
continue;
err = nft_flow_offload_rule(trans->ctx.chain,
nft_trans_rule(trans),
nft_trans_flow_rule(trans),
FLOW_CLS_REPLACE);
break;
}
if (WARN_ON_ONCE(err))
break;
}
}
int nft_flow_rule_offload_commit(struct net *net) int nft_flow_rule_offload_commit(struct net *net)
{ {
struct nft_trans *trans; struct nft_trans *trans;
...@@ -418,14 +471,14 @@ int nft_flow_rule_offload_commit(struct net *net) ...@@ -418,14 +471,14 @@ int nft_flow_rule_offload_commit(struct net *net)
continue; continue;
if (trans->ctx.flags & NLM_F_REPLACE || if (trans->ctx.flags & NLM_F_REPLACE ||
!(trans->ctx.flags & NLM_F_APPEND)) !(trans->ctx.flags & NLM_F_APPEND)) {
return -EOPNOTSUPP; err = -EOPNOTSUPP;
break;
}
err = nft_flow_offload_rule(trans->ctx.chain, err = nft_flow_offload_rule(trans->ctx.chain,
nft_trans_rule(trans), nft_trans_rule(trans),
nft_trans_flow_rule(trans), nft_trans_flow_rule(trans),
FLOW_CLS_REPLACE); FLOW_CLS_REPLACE);
nft_flow_rule_destroy(nft_trans_flow_rule(trans));
break; break;
case NFT_MSG_DELRULE: case NFT_MSG_DELRULE:
if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD)) if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
...@@ -433,13 +486,31 @@ int nft_flow_rule_offload_commit(struct net *net) ...@@ -433,13 +486,31 @@ int nft_flow_rule_offload_commit(struct net *net)
err = nft_flow_offload_rule(trans->ctx.chain, err = nft_flow_offload_rule(trans->ctx.chain,
nft_trans_rule(trans), nft_trans_rule(trans),
nft_trans_flow_rule(trans), NULL, FLOW_CLS_DESTROY);
FLOW_CLS_DESTROY);
break; break;
} }
if (err) if (err) {
return err; nft_flow_rule_offload_abort(net, trans);
break;
}
}
list_for_each_entry(trans, &net->nft.commit_list, list) {
if (trans->ctx.family != NFPROTO_NETDEV)
continue;
switch (trans->msg_type) {
case NFT_MSG_NEWRULE:
case NFT_MSG_DELRULE:
if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
continue;
nft_flow_rule_destroy(nft_trans_flow_rule(trans));
break;
default:
break;
}
} }
return err; return err;
......
...@@ -33,19 +33,19 @@ ...@@ -33,19 +33,19 @@
static DEFINE_PER_CPU(struct rnd_state, nft_prandom_state); static DEFINE_PER_CPU(struct rnd_state, nft_prandom_state);
static u8 nft_meta_weekday(unsigned long secs) static u8 nft_meta_weekday(time64_t secs)
{ {
unsigned int dse; unsigned int dse;
u8 wday; u8 wday;
secs -= NFT_META_SECS_PER_MINUTE * sys_tz.tz_minuteswest; secs -= NFT_META_SECS_PER_MINUTE * sys_tz.tz_minuteswest;
dse = secs / NFT_META_SECS_PER_DAY; dse = div_u64(secs, NFT_META_SECS_PER_DAY);
wday = (4 + dse) % NFT_META_DAYS_PER_WEEK; wday = (4 + dse) % NFT_META_DAYS_PER_WEEK;
return wday; return wday;
} }
static u32 nft_meta_hour(unsigned long secs) static u32 nft_meta_hour(time64_t secs)
{ {
struct tm tm; struct tm tm;
...@@ -250,10 +250,10 @@ void nft_meta_get_eval(const struct nft_expr *expr, ...@@ -250,10 +250,10 @@ void nft_meta_get_eval(const struct nft_expr *expr,
nft_reg_store64(dest, ktime_get_real_ns()); nft_reg_store64(dest, ktime_get_real_ns());
break; break;
case NFT_META_TIME_DAY: case NFT_META_TIME_DAY:
nft_reg_store8(dest, nft_meta_weekday(get_seconds())); nft_reg_store8(dest, nft_meta_weekday(ktime_get_real_seconds()));
break; break;
case NFT_META_TIME_HOUR: case NFT_META_TIME_HOUR:
*dest = nft_meta_hour(get_seconds()); *dest = nft_meta_hour(ktime_get_real_seconds());
break; break;
default: default:
WARN_ON(1); WARN_ON(1);
...@@ -547,6 +547,10 @@ static int nft_meta_get_offload(struct nft_offload_ctx *ctx, ...@@ -547,6 +547,10 @@ static int nft_meta_get_offload(struct nft_offload_ctx *ctx,
sizeof(__u8), reg); sizeof(__u8), reg);
nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_TRANSPORT); nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_TRANSPORT);
break; break;
case NFT_META_IIF:
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_META, meta,
ingress_ifindex, sizeof(__u32), reg);
break;
default: default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -23,50 +23,58 @@ ...@@ -23,50 +23,58 @@
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/ipv6.h> #include <linux/ipv6.h>
static bool nft_payload_rebuild_vlan_hdr(const struct sk_buff *skb, int mac_off,
struct vlan_ethhdr *veth)
{
if (skb_copy_bits(skb, mac_off, veth, ETH_HLEN))
return false;
veth->h_vlan_proto = skb->vlan_proto;
veth->h_vlan_TCI = htons(skb_vlan_tag_get(skb));
veth->h_vlan_encapsulated_proto = skb->protocol;
return true;
}
/* add vlan header into the user buffer for if tag was removed by offloads */ /* add vlan header into the user buffer for if tag was removed by offloads */
static bool static bool
nft_payload_copy_vlan(u32 *d, const struct sk_buff *skb, u8 offset, u8 len) nft_payload_copy_vlan(u32 *d, const struct sk_buff *skb, u8 offset, u8 len)
{ {
int mac_off = skb_mac_header(skb) - skb->data; int mac_off = skb_mac_header(skb) - skb->data;
u8 vlan_len, *vlanh, *dst_u8 = (u8 *) d; u8 *vlanh, *dst_u8 = (u8 *) d;
struct vlan_ethhdr veth; struct vlan_ethhdr veth;
u8 vlan_hlen = 0;
if ((skb->protocol == htons(ETH_P_8021AD) ||
skb->protocol == htons(ETH_P_8021Q)) &&
offset >= VLAN_ETH_HLEN && offset < VLAN_ETH_HLEN + VLAN_HLEN)
vlan_hlen += VLAN_HLEN;
vlanh = (u8 *) &veth; vlanh = (u8 *) &veth;
if (offset < ETH_HLEN) { if (offset < VLAN_ETH_HLEN + vlan_hlen) {
u8 ethlen = min_t(u8, len, ETH_HLEN - offset); u8 ethlen = len;
if (skb_copy_bits(skb, mac_off, &veth, ETH_HLEN)) if (vlan_hlen &&
skb_copy_bits(skb, mac_off, &veth, VLAN_ETH_HLEN) < 0)
return false;
else if (!nft_payload_rebuild_vlan_hdr(skb, mac_off, &veth))
return false; return false;
veth.h_vlan_proto = skb->vlan_proto; if (offset + len > VLAN_ETH_HLEN + vlan_hlen)
ethlen -= offset + len - VLAN_ETH_HLEN + vlan_hlen;
memcpy(dst_u8, vlanh + offset, ethlen); memcpy(dst_u8, vlanh + offset - vlan_hlen, ethlen);
len -= ethlen; len -= ethlen;
if (len == 0) if (len == 0)
return true; return true;
dst_u8 += ethlen; dst_u8 += ethlen;
offset = ETH_HLEN; offset = ETH_HLEN + vlan_hlen;
} else if (offset >= VLAN_ETH_HLEN) { } else {
offset -= VLAN_HLEN; offset -= VLAN_HLEN + vlan_hlen;
goto skip;
} }
veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
veth.h_vlan_encapsulated_proto = skb->protocol;
vlanh += offset;
vlan_len = min_t(u8, len, VLAN_ETH_HLEN - offset);
memcpy(dst_u8, vlanh, vlan_len);
len -= vlan_len;
if (!len)
return true;
dst_u8 += vlan_len;
skip:
return skb_copy_bits(skb, offset + mac_off, dst_u8, len) == 0; return skb_copy_bits(skb, offset + mac_off, dst_u8, len) == 0;
} }
......
...@@ -77,12 +77,12 @@ static inline bool is_leap(unsigned int y) ...@@ -77,12 +77,12 @@ static inline bool is_leap(unsigned int y)
* This is done in three separate functions so that the most expensive * This is done in three separate functions so that the most expensive
* calculations are done last, in case a "simple match" can be found earlier. * calculations are done last, in case a "simple match" can be found earlier.
*/ */
static inline unsigned int localtime_1(struct xtm *r, time_t time) static inline unsigned int localtime_1(struct xtm *r, time64_t time)
{ {
unsigned int v, w; unsigned int v, w;
/* Each day has 86400s, so finding the hour/minute is actually easy. */ /* Each day has 86400s, so finding the hour/minute is actually easy. */
v = time % SECONDS_PER_DAY; div_u64_rem(time, SECONDS_PER_DAY, &v);
r->second = v % 60; r->second = v % 60;
w = v / 60; w = v / 60;
r->minute = w % 60; r->minute = w % 60;
...@@ -90,13 +90,13 @@ static inline unsigned int localtime_1(struct xtm *r, time_t time) ...@@ -90,13 +90,13 @@ static inline unsigned int localtime_1(struct xtm *r, time_t time)
return v; return v;
} }
static inline void localtime_2(struct xtm *r, time_t time) static inline void localtime_2(struct xtm *r, time64_t time)
{ {
/* /*
* Here comes the rest (weekday, monthday). First, divide the SSTE * Here comes the rest (weekday, monthday). First, divide the SSTE
* by seconds-per-day to get the number of _days_ since the epoch. * by seconds-per-day to get the number of _days_ since the epoch.
*/ */
r->dse = time / 86400; r->dse = div_u64(time, SECONDS_PER_DAY);
/* /*
* 1970-01-01 (w=0) was a Thursday (4). * 1970-01-01 (w=0) was a Thursday (4).
...@@ -105,7 +105,7 @@ static inline void localtime_2(struct xtm *r, time_t time) ...@@ -105,7 +105,7 @@ static inline void localtime_2(struct xtm *r, time_t time)
r->weekday = (4 + r->dse - 1) % 7 + 1; r->weekday = (4 + r->dse - 1) % 7 + 1;
} }
static void localtime_3(struct xtm *r, time_t time) static void localtime_3(struct xtm *r, time64_t time)
{ {
unsigned int year, i, w = r->dse; unsigned int year, i, w = r->dse;
...@@ -160,7 +160,7 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -160,7 +160,7 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par)
const struct xt_time_info *info = par->matchinfo; const struct xt_time_info *info = par->matchinfo;
unsigned int packet_time; unsigned int packet_time;
struct xtm current_time; struct xtm current_time;
s64 stamp; time64_t stamp;
/* /*
* We need real time here, but we can neither use skb->tstamp * We need real time here, but we can neither use skb->tstamp
...@@ -173,14 +173,14 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -173,14 +173,14 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par)
* 1. match before 13:00 * 1. match before 13:00
* 2. match after 13:00 * 2. match after 13:00
* *
* If you match against processing time (get_seconds) it * If you match against processing time (ktime_get_real_seconds) it
* may happen that the same packet matches both rules if * may happen that the same packet matches both rules if
* it arrived at the right moment before 13:00, so it would be * it arrived at the right moment before 13:00, so it would be
* better to check skb->tstamp and set it via __net_timestamp() * better to check skb->tstamp and set it via __net_timestamp()
* if needed. This however breaks outgoing packets tx timestamp, * if needed. This however breaks outgoing packets tx timestamp,
* and causes them to get delayed forever by fq packet scheduler. * and causes them to get delayed forever by fq packet scheduler.
*/ */
stamp = get_seconds(); stamp = ktime_get_real_seconds();
if (info->flags & XT_TIME_LOCAL_TZ) if (info->flags & XT_TIME_LOCAL_TZ)
/* Adjust for local timezone */ /* Adjust for local timezone */
...@@ -193,6 +193,9 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -193,6 +193,9 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par)
* - 'now' is in the weekday mask * - 'now' is in the weekday mask
* - 'now' is in the daytime range time_start..time_end * - 'now' is in the daytime range time_start..time_end
* (and by default, libxt_time will set these so as to match) * (and by default, libxt_time will set these so as to match)
*
* note: info->date_start/stop are unsigned 32-bit values that
* can hold values beyond y2038, but not after y2106.
*/ */
if (stamp < info->date_start || stamp > info->date_stop) if (stamp < info->date_start || stamp > info->date_stop)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment