Skip to content

Commit cdc9f94

Browse files
Yuval Mintzdavem330
authored andcommitted
ipmr: Make ipmr_dump() common
Since all the primitive elements used for the notification done by ipmr are now common [mr_table, mr_mfc, vif_device] we can refactor the logic for dumping them to a common file. Signed-off-by: Yuval Mintz <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 54c4cad commit cdc9f94

File tree

3 files changed

+62
-51
lines changed

3 files changed

+62
-51
lines changed

include/linux/mroute_base.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ int mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
277277
u32 portid, u32 seq, struct mr_mfc *c,
278278
int cmd, int flags),
279279
spinlock_t *lock);
280+
281+
int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family,
282+
int (*rules_dump)(struct net *net,
283+
struct notifier_block *nb),
284+
struct mr_table *(*mr_iter)(struct net *net,
285+
struct mr_table *mrt),
286+
rwlock_t *mrt_lock);
280287
#else
281288
static inline void vif_device_init(struct vif_device *v,
282289
struct net_device *dev,
@@ -333,6 +340,17 @@ mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
333340
{
334341
return -EINVAL;
335342
}
343+
344+
static inline int mr_dump(struct net *net, struct notifier_block *nb,
345+
unsigned short family,
346+
int (*rules_dump)(struct net *net,
347+
struct notifier_block *nb),
348+
struct mr_table *(*mr_iter)(struct net *net,
349+
struct mr_table *mrt),
350+
rwlock_t *mrt_lock)
351+
{
352+
return -EINVAL;
353+
}
336354
#endif
337355

338356
static inline void *mr_mfc_find(struct mr_table *mrt, void *hasharg)

net/ipv4/ipmr.c

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -644,16 +644,6 @@ static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt)
644644
}
645645
#endif
646646

647-
static int call_ipmr_vif_entry_notifier(struct notifier_block *nb,
648-
struct net *net,
649-
enum fib_event_type event_type,
650-
struct vif_device *vif,
651-
vifi_t vif_index, u32 tb_id)
652-
{
653-
return mr_call_vif_notifier(nb, net, RTNL_FAMILY_IPMR, event_type,
654-
vif, vif_index, tb_id);
655-
}
656-
657647
static int call_ipmr_vif_entry_notifiers(struct net *net,
658648
enum fib_event_type event_type,
659649
struct vif_device *vif,
@@ -664,15 +654,6 @@ static int call_ipmr_vif_entry_notifiers(struct net *net,
664654
&net->ipv4.ipmr_seq);
665655
}
666656

667-
static int call_ipmr_mfc_entry_notifier(struct notifier_block *nb,
668-
struct net *net,
669-
enum fib_event_type event_type,
670-
struct mfc_cache *mfc, u32 tb_id)
671-
{
672-
return mr_call_mfc_notifier(nb, net, RTNL_FAMILY_IPMR,
673-
event_type, &mfc->_c, tb_id);
674-
}
675-
676657
static int call_ipmr_mfc_entry_notifiers(struct net *net,
677658
enum fib_event_type event_type,
678659
struct mfc_cache *mfc, u32 tb_id)
@@ -2950,38 +2931,8 @@ static unsigned int ipmr_seq_read(struct net *net)
29502931

29512932
static int ipmr_dump(struct net *net, struct notifier_block *nb)
29522933
{
2953-
struct mr_table *mrt;
2954-
int err;
2955-
2956-
err = ipmr_rules_dump(net, nb);
2957-
if (err)
2958-
return err;
2959-
2960-
ipmr_for_each_table(mrt, net) {
2961-
struct vif_device *v = &mrt->vif_table[0];
2962-
struct mr_mfc *mfc;
2963-
int vifi;
2964-
2965-
/* Notifiy on table VIF entries */
2966-
read_lock(&mrt_lock);
2967-
for (vifi = 0; vifi < mrt->maxvif; vifi++, v++) {
2968-
if (!v->dev)
2969-
continue;
2970-
2971-
call_ipmr_vif_entry_notifier(nb, net, FIB_EVENT_VIF_ADD,
2972-
v, vifi, mrt->id);
2973-
}
2974-
read_unlock(&mrt_lock);
2975-
2976-
/* Notify on table MFC entries */
2977-
list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list)
2978-
call_ipmr_mfc_entry_notifier(nb, net,
2979-
FIB_EVENT_ENTRY_ADD,
2980-
(struct mfc_cache *)mfc,
2981-
mrt->id);
2982-
}
2983-
2984-
return 0;
2934+
return mr_dump(net, nb, RTNL_FAMILY_IPMR, ipmr_rules_dump,
2935+
ipmr_mr_table_iter, &mrt_lock);
29852936
}
29862937

29872938
static const struct fib_notifier_ops ipmr_notifier_ops_template = {

net/ipv4/ipmr_base.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,45 @@ int mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
321321
return skb->len;
322322
}
323323
EXPORT_SYMBOL(mr_rtm_dumproute);
324+
325+
int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family,
326+
int (*rules_dump)(struct net *net,
327+
struct notifier_block *nb),
328+
struct mr_table *(*mr_iter)(struct net *net,
329+
struct mr_table *mrt),
330+
rwlock_t *mrt_lock)
331+
{
332+
struct mr_table *mrt;
333+
int err;
334+
335+
err = rules_dump(net, nb);
336+
if (err)
337+
return err;
338+
339+
for (mrt = mr_iter(net, NULL); mrt; mrt = mr_iter(net, mrt)) {
340+
struct vif_device *v = &mrt->vif_table[0];
341+
struct mr_mfc *mfc;
342+
int vifi;
343+
344+
/* Notifiy on table VIF entries */
345+
read_lock(mrt_lock);
346+
for (vifi = 0; vifi < mrt->maxvif; vifi++, v++) {
347+
if (!v->dev)
348+
continue;
349+
350+
mr_call_vif_notifier(nb, net, family,
351+
FIB_EVENT_VIF_ADD,
352+
v, vifi, mrt->id);
353+
}
354+
read_unlock(mrt_lock);
355+
356+
/* Notify on table MFC entries */
357+
list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list)
358+
mr_call_mfc_notifier(nb, net, family,
359+
FIB_EVENT_ENTRY_ADD,
360+
mfc, mrt->id);
361+
}
362+
363+
return 0;
364+
}
365+
EXPORT_SYMBOL(mr_dump);

0 commit comments

Comments
 (0)