Skip to content
Permalink
Browse files
netfilter: make hook functions accept only one argument
BPF conversion requirement: one pointer-to-structure as argument.

Signed-off-by: Florian Westphal <fw@strlen.de>
  • Loading branch information
Florian Westphal authored and intel-lab-lkp committed Oct 14, 2021
1 parent 0fb6afa commit 95fd31a5f5e86a1918a80e1b99333877a09e1a4e
Show file tree
Hide file tree
Showing 37 changed files with 207 additions and 277 deletions.
@@ -90,9 +90,9 @@ static const struct l3mdev_ops ipvl_l3mdev_ops = {
.l3mdev_l3_rcv = ipvlan_l3_rcv,
};

static unsigned int ipvlan_nf_input(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int ipvlan_nf_input(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct ipvl_addr *addr;
unsigned int len;

@@ -65,6 +65,8 @@ struct nf_hook_ops;
struct sock;

struct nf_hook_state {
struct sk_buff *skb;
void *priv;
u8 hook;
u8 pf;
u16 hook_index; /* index in hook_entries->hook[] */
@@ -75,9 +77,7 @@ struct nf_hook_state {
int (*okfn)(struct net *, struct sock *, struct sk_buff *);
};

typedef unsigned int nf_hookfn(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state);
typedef unsigned int nf_hookfn(const struct nf_hook_state *state);
enum nf_hook_ops_type {
NF_HOOK_OP_UNDEFINED,
NF_HOOK_OP_NF_TABLES,
@@ -140,7 +140,9 @@ static inline int
nf_hook_entry_hookfn(const struct nf_hook_entry *entry, struct sk_buff *skb,
struct nf_hook_state *state)
{
return entry->hook(entry->priv, skb, state);
state->skb = skb;
state->priv = entry->priv;
return entry->hook(state);
}

static inline void nf_hook_state_init(struct nf_hook_state *p,
@@ -57,18 +57,15 @@ struct net_device *setup_pre_routing(struct sk_buff *skb,

#if IS_ENABLED(CONFIG_IPV6)
int br_validate_ipv6(struct net *net, struct sk_buff *skb);
unsigned int br_nf_pre_routing_ipv6(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state);
unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_state *state);
#else
static inline int br_validate_ipv6(struct net *net, struct sk_buff *skb)
{
return -1;
}

static inline unsigned int
br_nf_pre_routing_ipv6(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
br_nf_pre_routing_ipv6(const struct nf_hook_state *state)
{
return NF_ACCEPT;
}
@@ -284,10 +284,8 @@ struct flow_ports {
__be16 source, dest;
};

unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state);
unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state);
unsigned int nf_flow_offload_ip_hook(const struct nf_hook_state *state);
unsigned int nf_flow_offload_ipv6_hook(const struct nf_hook_state *state);

#define MODULE_ALIAS_NF_FLOWTABLE(family) \
MODULE_ALIAS("nf-flowtable-" __stringify(family))
@@ -60,8 +60,7 @@ bool synproxy_recv_client_ack(struct net *net,

struct nf_hook_state;

unsigned int ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *nhs);
unsigned int ipv4_synproxy_hook(const struct nf_hook_state *nhs);
int nf_synproxy_ipv4_init(struct synproxy_net *snet, struct net *net);
void nf_synproxy_ipv4_fini(struct synproxy_net *snet, struct net *net);

@@ -75,8 +74,7 @@ bool synproxy_recv_client_ack_ipv6(struct net *net, const struct sk_buff *skb,
const struct tcphdr *th,
struct synproxy_options *opts, u32 recv_seq);

unsigned int ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *nhs);
unsigned int ipv6_synproxy_hook(const struct nf_hook_state *nhs);
int nf_synproxy_ipv6_init(struct synproxy_net *snet, struct net *net);
void nf_synproxy_ipv6_fini(struct synproxy_net *snet, struct net *net);
#else
@@ -472,10 +472,9 @@ struct net_device *setup_pre_routing(struct sk_buff *skb, const struct net *net)
* receiving device) to make netfilter happy, the REDIRECT
* target in particular. Save the original destination IP
* address to be able to detect DNAT afterwards. */
static unsigned int br_nf_pre_routing(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int br_nf_pre_routing(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct nf_bridge_info *nf_bridge;
struct net_bridge_port *p;
struct net_bridge *br;
@@ -502,7 +501,7 @@ static unsigned int br_nf_pre_routing(void *priv,
}

nf_bridge_pull_encap_header_rcsum(skb);
return br_nf_pre_routing_ipv6(priv, skb, state);
return br_nf_pre_routing_ipv6(state);
}

if (!brnet->call_iptables && !br_opt_get(br, BROPT_NF_CALL_IPTABLES))
@@ -572,10 +571,9 @@ static int br_nf_forward_finish(struct net *net, struct sock *sk, struct sk_buff
* but we are still able to filter on the 'real' indev/outdev
* because of the physdev module. For ARP, indev and outdev are the
* bridge ports. */
static unsigned int br_nf_forward_ip(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int br_nf_forward_ip(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct nf_bridge_info *nf_bridge;
struct net_device *parent;
u_int8_t pf;
@@ -638,10 +636,9 @@ static unsigned int br_nf_forward_ip(void *priv,
return NF_STOLEN;
}

static unsigned int br_nf_forward_arp(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int br_nf_forward_arp(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct net_bridge_port *p;
struct net_bridge *br;
struct net_device **d = (struct net_device **)(skb->cb);
@@ -812,10 +809,9 @@ static int br_nf_dev_queue_xmit(struct net *net, struct sock *sk, struct sk_buff
}

/* PF_BRIDGE/POST_ROUTING ********************************************/
static unsigned int br_nf_post_routing(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int br_nf_post_routing(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
struct net_device *realoutdev = bridge_parent(skb->dev);
u_int8_t pf;
@@ -861,10 +857,9 @@ static unsigned int br_nf_post_routing(void *priv,
/* IP/SABOTAGE *****************************************************/
/* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING
* for the second time. */
static unsigned int ip_sabotage_in(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int ip_sabotage_in(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);

if (nf_bridge && !nf_bridge->in_prerouting &&
@@ -212,11 +212,10 @@ static int br_nf_pre_routing_finish_ipv6(struct net *net, struct sock *sk, struc
/* Replicate the checks that IPv6 does on packet reception and pass the packet
* to ip6tables.
*/
unsigned int br_nf_pre_routing_ipv6(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_state *state)
{
struct nf_bridge_info *nf_bridge;
struct sk_buff *skb = state->skb;

if (br_validate_ipv6(state->net, skb))
return NF_DROP;
@@ -51,9 +51,9 @@ static const struct ebt_table broute_table = {
.me = THIS_MODULE,
};

static unsigned int ebt_broute(void *priv, struct sk_buff *skb,
const struct nf_hook_state *s)
static unsigned int ebt_broute(const struct nf_hook_state *s)
{
struct sk_buff *skb = s->skb;
struct net_bridge_port *p = br_port_get_rcu(skb->dev);
struct nf_hook_state state;
unsigned char *dest;
@@ -66,7 +66,9 @@ static unsigned int ebt_broute(void *priv, struct sk_buff *skb,
NFPROTO_BRIDGE, s->in, NULL, NULL,
s->net, NULL);

ret = ebt_do_table(skb, &state, priv);
state.skb = skb;
state.priv = s->priv;
ret = ebt_do_table(skb, &state, s->priv);
if (ret != NF_DROP)
return ret;

@@ -59,10 +59,9 @@ static const struct ebt_table frame_filter = {
};

static unsigned int
ebt_filter_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
ebt_filter_hook(const struct nf_hook_state *state)
{
return ebt_do_table(skb, state, priv);
return ebt_do_table(state->skb, state, state->priv);
}

static const struct nf_hook_ops ebt_ops_filter[] = {
@@ -58,10 +58,9 @@ static const struct ebt_table frame_nat = {
.me = THIS_MODULE,
};

static unsigned int ebt_nat_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int ebt_nat_hook(const struct nf_hook_state *state)
{
return ebt_do_table(skb, state, priv);
return ebt_do_table(state->skb, state, state->priv);
}

static const struct nf_hook_ops ebt_ops_nat[] = {
@@ -236,10 +236,10 @@ static int nf_ct_br_ipv6_check(const struct sk_buff *skb)
return 0;
}

static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int nf_ct_bridge_pre(const struct nf_hook_state *state)
{
struct nf_hook_state bridge_state = *state;
struct sk_buff *skb = state->skb;
enum ip_conntrack_info ctinfo;
struct nf_conn *ct;
u32 len;
@@ -395,9 +395,9 @@ static unsigned int nf_ct_bridge_confirm(struct sk_buff *skb)
return nf_confirm(skb, protoff, ct, ctinfo);
}

static unsigned int nf_ct_bridge_post(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int nf_ct_bridge_post(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
int ret;

ret = nf_ct_bridge_confirm(skb);
@@ -28,10 +28,9 @@ static const struct xt_table packet_filter = {

/* The work comes in here from netfilter.c */
static unsigned int
arptable_filter_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
arptable_filter_hook(const struct nf_hook_state *state)
{
return arpt_do_table(skb, state, priv);
return arpt_do_table(state->skb, state, state->priv);
}

static struct nf_hook_ops *arpfilter_ops __read_mostly;
@@ -75,7 +75,7 @@ struct clusterip_net {
unsigned int hook_users;
};

static unsigned int clusterip_arp_mangle(void *priv, struct sk_buff *skb, const struct nf_hook_state *state);
static unsigned int clusterip_arp_mangle(const struct nf_hook_state *state);

static const struct nf_hook_ops cip_arp_ops = {
.hook = clusterip_arp_mangle,
@@ -635,9 +635,9 @@ static void arp_print(struct arp_payload *payload)
#endif

static unsigned int
clusterip_arp_mangle(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
clusterip_arp_mangle(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct arphdr *arp = arp_hdr(skb);
struct arp_payload *payload;
struct clusterip_config *c;
@@ -29,10 +29,9 @@ static const struct xt_table packet_filter = {
};

static unsigned int
iptable_filter_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
iptable_filter_hook(const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
return ipt_do_table(state->skb, state, state->priv);
}

static struct nf_hook_ops *filter_ops __read_mostly;
@@ -70,10 +70,11 @@ ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state, void *pri

/* The work comes in here from netfilter.c. */
static unsigned int
iptable_mangle_hook(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
iptable_mangle_hook(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
void *priv = state->priv;

if (state->hook == NF_INET_LOCAL_OUT)
return ipt_mangle_out(skb, state, priv);
return ipt_do_table(skb, state, priv);
@@ -29,11 +29,9 @@ static const struct xt_table nf_nat_ipv4_table = {
.af = NFPROTO_IPV4,
};

static unsigned int iptable_nat_do_chain(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int iptable_nat_do_chain(const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
return ipt_do_table(state->skb, state, state->priv);
}

static const struct nf_hook_ops nf_nat_ipv4_ops[] = {
@@ -34,10 +34,9 @@ static const struct xt_table packet_raw_before_defrag = {

/* The work comes in here from netfilter.c. */
static unsigned int
iptable_raw_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
iptable_raw_hook(const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
return ipt_do_table(state->skb, state, state->priv);
}

static struct nf_hook_ops *rawtable_ops __read_mostly;
@@ -34,10 +34,9 @@ static const struct xt_table security_table = {
};

static unsigned int
iptable_security_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
iptable_security_hook(const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
return ipt_do_table(state->skb, state, state->priv);
}

static struct nf_hook_ops *sectbl_ops __read_mostly;
@@ -63,10 +63,9 @@ static enum ip_defrag_users nf_ct_defrag_user(unsigned int hooknum,
return IP_DEFRAG_CONNTRACK_OUT + zone_id;
}

static unsigned int ipv4_conntrack_defrag(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
static unsigned int ipv4_conntrack_defrag(const struct nf_hook_state *state)
{
struct sk_buff *skb = state->skb;
struct sock *sk = skb->sk;

if (sk && sk_fullsock(sk) && (sk->sk_family == PF_INET) &&
@@ -29,10 +29,9 @@ static const struct xt_table packet_filter = {

/* The work comes in here from netfilter.c. */
static unsigned int
ip6table_filter_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
ip6table_filter_hook(const struct nf_hook_state *state)
{
return ip6t_do_table(skb, state, priv);
return ip6t_do_table(state->skb, state, state->priv);
}

static struct nf_hook_ops *filter_ops __read_mostly;

0 comments on commit 95fd31a

Please sign in to comment.