Skip to content

Commit 426b530

Browse files
ebiedermdavem330
authored andcommitted
[NETNS]: Modify the neighbour table code so it handles multiple network namespaces
I'm actually surprised at how much was involved. At first glance it appears that the neighbour table data structures are already split by network device so all that should be needed is to modify the user interface commands to filter the set of neighbours by the network namespace of their devices. However a couple things turned up while I was reading through the code. The proxy neighbour table allows entries with no network device, and the neighbour parms are per network device (except for the defaults) so they now need a per network namespace default. So I updated the two structures (which surprised me) with their very own network namespace parameter. Updated the relevant lookup and destroy routines with a network namespace parameter and modified the code that interacts with users to filter out neighbour table entries for devices of other namespaces. I'm a little concerned that we can modify and display the global table configuration and from all network namespaces. But this appears good enough for now. I keep thinking modifying the neighbour table to have per network namespace instances of each table type would should be cleaner. The hash table is already dynamically sized so there are it is not a limiter. The default parameter would be straight forward to take care of. However when I look at the how the network table is built and used I still find some assumptions that there is only a single neighbour table for each type of table in the kernel. The netlink operations, neigh_seq_start, the non-core network users that call neigh_lookup. So while it might be doable it would require more refactoring than my current approach of just doing a little extra filtering in the code. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e1af9f2 commit 426b530

8 files changed

Lines changed: 106 additions & 61 deletions

File tree

‎include/net/neighbour.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct neighbour;
3434

3535
struct neigh_parms
3636
{
37+
struct net *net;
3738
struct net_device *dev;
3839
struct neigh_parms *next;
3940
int (*neigh_setup)(struct neighbour *);
@@ -126,7 +127,8 @@ struct neigh_ops
126127
struct pneigh_entry
127128
{
128129
struct pneigh_entry *next;
129-
struct net_device *dev;
130+
struct net *net;
131+
struct net_device *dev;
130132
u8 flags;
131133
u8 key[0];
132134
};
@@ -187,6 +189,7 @@ extern struct neighbour * neigh_lookup(struct neigh_table *tbl,
187189
const void *pkey,
188190
struct net_device *dev);
189191
extern struct neighbour * neigh_lookup_nodev(struct neigh_table *tbl,
192+
struct net *net,
190193
const void *pkey);
191194
extern struct neighbour * neigh_create(struct neigh_table *tbl,
192195
const void *pkey,
@@ -211,15 +214,16 @@ extern unsigned long neigh_rand_reach_time(unsigned long base);
211214

212215
extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
213216
struct sk_buff *skb);
214-
extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev, int creat);
215-
extern int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev);
217+
extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev, int creat);
218+
extern int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev);
216219

217220
extern void neigh_app_ns(struct neighbour *n);
218221
extern void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie);
219222
extern void __neigh_for_each_release(struct neigh_table *tbl, int (*cb)(struct neighbour *));
220223
extern void pneigh_for_each(struct neigh_table *tbl, void (*cb)(struct pneigh_entry *));
221224

222225
struct neigh_seq_state {
226+
struct net *net;
223227
struct neigh_table *tbl;
224228
void *(*neigh_sub_iter)(struct neigh_seq_state *state,
225229
struct neighbour *n, loff_t *pos);

‎net/atm/clip.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,11 @@ static int arp_seq_open(struct inode *inode, struct file *file)
949949

950950
seq = file->private_data;
951951
seq->private = state;
952+
state->ns.net = get_proc_net(inode);
953+
if (!state->ns.net) {
954+
seq_release_private(inode, file);
955+
rc = -ENXIO;
956+
}
952957
out:
953958
return rc;
954959

@@ -957,11 +962,19 @@ static int arp_seq_open(struct inode *inode, struct file *file)
957962
goto out;
958963
}
959964

965+
static int arp_seq_release(struct inode *inode, struct file *file)
966+
{
967+
struct seq_file *seq = file->private_data;
968+
struct clip_seq_state *state = seq->private;
969+
put_net(state->ns.net);
970+
return seq_release_private(inode, file);
971+
}
972+
960973
static const struct file_operations arp_seq_fops = {
961974
.open = arp_seq_open,
962975
.read = seq_read,
963976
.llseek = seq_lseek,
964-
.release = seq_release_private,
977+
.release = arp_seq_release,
965978
.owner = THIS_MODULE
966979
};
967980
#endif

0 commit comments

Comments
 (0)