Skip to content

Commit 9ecf07a

Browse files
miniplidavem330
authored andcommitted
neigh: sysctl - simplify address calculation of gc_* variables
The code in neigh_sysctl_register() relies on a specific layout of struct neigh_table, namely that the 'gc_*' variables are directly following the 'parms' member in a specific order. The code, though, expresses this in the most ugly way. Get rid of the ugly casts and use the 'tbl' pointer to get a handle to the table. This way we can refer to the 'gc_*' variables directly. Similarly seen in the grsecurity patch, written by Brad Spengler. Signed-off-by: Mathias Krause <minipli@googlemail.com> Cc: Brad Spengler <spender@grsecurity.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8f2e5ae commit 9ecf07a

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎include/net/neighbour.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ struct neigh_table {
203203
void (*proxy_redo)(struct sk_buff *skb);
204204
char *id;
205205
struct neigh_parms parms;
206-
/* HACK. gc_* should follow parms without a gap! */
207206
int gc_interval;
208207
int gc_thresh1;
209208
int gc_thresh2;

‎net/core/neighbour.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
30593059
memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
30603060
sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
30613061
} else {
3062+
struct neigh_table *tbl = p->tbl;
30623063
dev_name_source = "default";
3063-
t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
3064-
t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
3065-
t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
3066-
t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
3064+
t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &tbl->gc_interval;
3065+
t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &tbl->gc_thresh1;
3066+
t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &tbl->gc_thresh2;
3067+
t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &tbl->gc_thresh3;
30673068
}
30683069

30693070
if (handler) {

0 commit comments

Comments
 (0)