Skip to content

Commit 2f3a527

Browse files
idoschdavem330
authored andcommitted
ipv4: fib: Add events for FIB replace and append
The FIB notification chain currently uses the NLM_F_{REPLACE,APPEND} flags to signal routes being replaced or appended. Instead of using netlink flags for in-kernel notifications we can simply introduce two new events in the FIB notification chain. This has the added advantage of making the API cleaner, thereby making it clear that these events should be supported by listeners of the notification chain. Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> CC: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5b7d616 commit 2f3a527

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

include/net/ip_fib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ struct fib_entry_notifier_info {
211211
u8 tos;
212212
u8 type;
213213
u32 tb_id;
214-
u32 nlflags;
215214
};
216215

217216
struct fib_nh_notifier_info {
@@ -220,6 +219,8 @@ struct fib_nh_notifier_info {
220219
};
221220

222221
enum fib_event_type {
222+
FIB_EVENT_ENTRY_REPLACE,
223+
FIB_EVENT_ENTRY_APPEND,
223224
FIB_EVENT_ENTRY_ADD,
224225
FIB_EVENT_ENTRY_DEL,
225226
FIB_EVENT_RULE_ADD,

net/ipv4/fib_trie.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void fib_notify(struct net *net, struct notifier_block *nb,
124124
static int call_fib_entry_notifier(struct notifier_block *nb, struct net *net,
125125
enum fib_event_type event_type, u32 dst,
126126
int dst_len, struct fib_info *fi,
127-
u8 tos, u8 type, u32 tb_id, u32 nlflags)
127+
u8 tos, u8 type, u32 tb_id)
128128
{
129129
struct fib_entry_notifier_info info = {
130130
.dst = dst,
@@ -133,7 +133,6 @@ static int call_fib_entry_notifier(struct notifier_block *nb, struct net *net,
133133
.tos = tos,
134134
.type = type,
135135
.tb_id = tb_id,
136-
.nlflags = nlflags,
137136
};
138137
return call_fib_notifier(nb, net, event_type, &info.info);
139138
}
@@ -197,7 +196,7 @@ int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
197196
static int call_fib_entry_notifiers(struct net *net,
198197
enum fib_event_type event_type, u32 dst,
199198
int dst_len, struct fib_info *fi,
200-
u8 tos, u8 type, u32 tb_id, u32 nlflags)
199+
u8 tos, u8 type, u32 tb_id)
201200
{
202201
struct fib_entry_notifier_info info = {
203202
.dst = dst,
@@ -206,7 +205,6 @@ static int call_fib_entry_notifiers(struct net *net,
206205
.tos = tos,
207206
.type = type,
208207
.tb_id = tb_id,
209-
.nlflags = nlflags,
210208
};
211209
return call_fib_notifiers(net, event_type, &info.info);
212210
}
@@ -1198,6 +1196,7 @@ static int fib_insert_alias(struct trie *t, struct key_vector *tp,
11981196
int fib_table_insert(struct net *net, struct fib_table *tb,
11991197
struct fib_config *cfg)
12001198
{
1199+
enum fib_event_type event = FIB_EVENT_ENTRY_ADD;
12011200
struct trie *t = (struct trie *)tb->tb_data;
12021201
struct fib_alias *fa, *new_fa;
12031202
struct key_vector *l, *tp;
@@ -1295,10 +1294,10 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
12951294
new_fa->tb_id = tb->tb_id;
12961295
new_fa->fa_default = -1;
12971296

1298-
call_fib_entry_notifiers(net, FIB_EVENT_ENTRY_ADD,
1297+
call_fib_entry_notifiers(net, FIB_EVENT_ENTRY_REPLACE,
12991298
key, plen, fi,
13001299
new_fa->fa_tos, cfg->fc_type,
1301-
tb->tb_id, nlflags);
1300+
tb->tb_id);
13021301
rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen,
13031302
tb->tb_id, &cfg->fc_nlinfo, nlflags);
13041303

@@ -1319,10 +1318,12 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
13191318
if (fa_match)
13201319
goto out;
13211320

1322-
if (cfg->fc_nlflags & NLM_F_APPEND)
1321+
if (cfg->fc_nlflags & NLM_F_APPEND) {
1322+
event = FIB_EVENT_ENTRY_APPEND;
13231323
nlflags |= NLM_F_APPEND;
1324-
else
1324+
} else {
13251325
fa = fa_first;
1326+
}
13261327
}
13271328
err = -ENOENT;
13281329
if (!(cfg->fc_nlflags & NLM_F_CREATE))
@@ -1351,8 +1352,8 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
13511352
tb->tb_num_default++;
13521353

13531354
rt_cache_flush(cfg->fc_nlinfo.nl_net);
1354-
call_fib_entry_notifiers(net, FIB_EVENT_ENTRY_ADD, key, plen, fi, tos,
1355-
cfg->fc_type, tb->tb_id, cfg->fc_nlflags);
1355+
call_fib_entry_notifiers(net, event, key, plen, fi, tos, cfg->fc_type,
1356+
tb->tb_id);
13561357
rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, new_fa->tb_id,
13571358
&cfg->fc_nlinfo, nlflags);
13581359
succeeded:
@@ -1654,7 +1655,7 @@ int fib_table_delete(struct net *net, struct fib_table *tb,
16541655

16551656
call_fib_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, key, plen,
16561657
fa_to_delete->fa_info, tos,
1657-
fa_to_delete->fa_type, tb->tb_id, 0);
1658+
fa_to_delete->fa_type, tb->tb_id);
16581659
rtmsg_fib(RTM_DELROUTE, htonl(key), fa_to_delete, plen, tb->tb_id,
16591660
&cfg->fc_nlinfo, 0);
16601661

@@ -1973,7 +1974,7 @@ int fib_table_flush(struct net *net, struct fib_table *tb)
19731974
n->key,
19741975
KEYLENGTH - fa->fa_slen,
19751976
fi, fa->fa_tos, fa->fa_type,
1976-
tb->tb_id, 0);
1977+
tb->tb_id);
19771978
hlist_del_rcu(&fa->fa_list);
19781979
fib_release_info(fa->fa_info);
19791980
alias_free_mem_rcu(fa);
@@ -2013,7 +2014,7 @@ static void fib_leaf_notify(struct net *net, struct key_vector *l,
20132014

20142015
call_fib_entry_notifier(nb, net, event_type, l->key,
20152016
KEYLENGTH - fa->fa_slen, fi, fa->fa_tos,
2016-
fa->fa_type, fa->tb_id, 0);
2017+
fa->fa_type, fa->tb_id);
20172018
}
20182019
}
20192020

0 commit comments

Comments
 (0)