Skip to content

Commit

Permalink
netns xfrm: per-netns NETLINK_XFRM socket
Browse files Browse the repository at this point in the history
Stub senders to init_net's one temporarily.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexey Dobriyan authored and David S. Miller committed Nov 26, 2008
1 parent bd235e3 commit a6483b7
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 44 deletions.
2 changes: 2 additions & 0 deletions include/net/netns/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct netns_xfrm {
struct xfrm_policy_hash policy_bydst[XFRM_POLICY_MAX * 2];
unsigned int policy_count[XFRM_POLICY_MAX * 2];
struct work_struct policy_hash_work;

struct sock *nlsk;
};

#endif
7 changes: 4 additions & 3 deletions include/net/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ DECLARE_SNMP_STAT(struct linux_xfrm_mib, xfrm_statistics);
#define XFRM_INC_STATS_USER(field)
#endif

extern struct sock *xfrm_nl;
extern u32 sysctl_xfrm_aevent_etime;
extern u32 sysctl_xfrm_aevent_rseqth;
extern int sysctl_xfrm_larval_drop;
Expand Down Expand Up @@ -1516,18 +1515,20 @@ static inline int xfrm_policy_id2dir(u32 index)
return index & 7;
}

static inline int xfrm_aevent_is_on(void)
#ifdef CONFIG_XFRM
static inline int xfrm_aevent_is_on(struct net *net)
{
struct sock *nlsk;
int ret = 0;

rcu_read_lock();
nlsk = rcu_dereference(xfrm_nl);
nlsk = rcu_dereference(net->xfrm.nlsk);
if (nlsk)
ret = netlink_has_listeners(nlsk, XFRMNLGRP_AEVENTS);
rcu_read_unlock();
return ret;
}
#endif

static inline int xfrm_alg_len(struct xfrm_algo *alg)
{
Expand Down
3 changes: 2 additions & 1 deletion net/xfrm/xfrm_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
{
struct dst_entry *dst = skb->dst;
struct xfrm_state *x = dst->xfrm;
struct net *net = xs_net(x);

if (err <= 0)
goto resume;
Expand Down Expand Up @@ -74,7 +75,7 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
err = -EOVERFLOW;
goto error;
}
if (xfrm_aevent_is_on())
if (xfrm_aevent_is_on(net))
xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
}

Expand Down
7 changes: 2 additions & 5 deletions net/xfrm/xfrm_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

#include "xfrm_hash.h"

struct sock *xfrm_nl;
EXPORT_SYMBOL(xfrm_nl);

u32 sysctl_xfrm_aevent_etime __read_mostly = XFRM_AE_ETIME;
EXPORT_SYMBOL(sysctl_xfrm_aevent_etime);

Expand Down Expand Up @@ -1659,7 +1656,7 @@ static void xfrm_replay_timer_handler(unsigned long data)
spin_lock(&x->lock);

if (x->km.state == XFRM_STATE_VALID) {
if (xfrm_aevent_is_on())
if (xfrm_aevent_is_on(xs_net(x)))
xfrm_replay_notify(x, XFRM_REPLAY_TIMEOUT);
else
x->xflags |= XFRM_TIME_DEFER;
Expand Down Expand Up @@ -1715,7 +1712,7 @@ void xfrm_replay_advance(struct xfrm_state *x, __be32 net_seq)
x->replay.bitmap |= (1U << diff);
}

if (xfrm_aevent_is_on())
if (xfrm_aevent_is_on(xs_net(x)))
xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
}

Expand Down
Loading

0 comments on commit a6483b7

Please sign in to comment.