Skip to content

Commit 6853f21

Browse files
Yuval Mintzdavem330
authored andcommitted
ipmr,ipmr6: Define a uniform vif_device
The two implementations have almost identical structures - vif_device and mif_device. As a step toward uniforming the mr_tables, eliminate the mif_device and relocate the vif_device definition into a new common header file. Also, introduce a common initializing function for setting most of the vif_device fields in a new common source file. This requires modifying the ipv{4,6] Kconfig and ipv4 makefile as we're introducing a new common config option - CONFIG_IP_MROUTE_COMMON. Signed-off-by: Yuval Mintz <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a25724b commit 6853f21

File tree

9 files changed

+117
-63
lines changed

9 files changed

+117
-63
lines changed

include/linux/mroute.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <net/fib_rules.h>
1010
#include <net/fib_notifier.h>
1111
#include <uapi/linux/mroute.h>
12+
#include <linux/mroute_base.h>
1213

1314
#ifdef CONFIG_IP_MROUTE
1415
static inline int ip_mroute_opt(int opt)
@@ -56,18 +57,6 @@ static inline bool ipmr_rule_default(const struct fib_rule *rule)
5657
}
5758
#endif
5859

59-
struct vif_device {
60-
struct net_device *dev; /* Device we are using */
61-
struct netdev_phys_item_id dev_parent_id; /* Device parent ID */
62-
unsigned long bytes_in,bytes_out;
63-
unsigned long pkt_in,pkt_out; /* Statistics */
64-
unsigned long rate_limit; /* Traffic shaping (NI) */
65-
unsigned char threshold; /* TTL threshold */
66-
unsigned short flags; /* Control flags */
67-
__be32 local,remote; /* Addresses(remote for tunnels)*/
68-
int link; /* Physical interface index */
69-
};
70-
7160
struct vif_entry_notifier_info {
7261
struct fib_notifier_info info;
7362
struct net_device *dev;

include/linux/mroute6.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/skbuff.h> /* for struct sk_buff_head */
88
#include <net/net_namespace.h>
99
#include <uapi/linux/mroute6.h>
10+
#include <linux/mroute_base.h>
1011

1112
#ifdef CONFIG_IPV6_MROUTE
1213
static inline int ip6_mroute_opt(int opt)
@@ -62,16 +63,6 @@ static inline void ip6_mr_cleanup(void)
6263
}
6364
#endif
6465

65-
struct mif_device {
66-
struct net_device *dev; /* Device we are using */
67-
unsigned long bytes_in,bytes_out;
68-
unsigned long pkt_in,pkt_out; /* Statistics */
69-
unsigned long rate_limit; /* Traffic shaping (NI) */
70-
unsigned char threshold; /* TTL threshold */
71-
unsigned short flags; /* Control flags */
72-
int link; /* Physical interface index */
73-
};
74-
7566
#define VIFF_STATIC 0x8000
7667

7768
struct mfc6_cache {

include/linux/mroute_base.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef __LINUX_MROUTE_BASE_H
2+
#define __LINUX_MROUTE_BASE_H
3+
4+
#include <linux/netdevice.h>
5+
6+
/**
7+
* struct vif_device - interface representor for multicast routing
8+
* @dev: network device being used
9+
* @bytes_in: statistic; bytes ingressing
10+
* @bytes_out: statistic; bytes egresing
11+
* @pkt_in: statistic; packets ingressing
12+
* @pkt_out: statistic; packets egressing
13+
* @rate_limit: Traffic shaping (NI)
14+
* @threshold: TTL threshold
15+
* @flags: Control flags
16+
* @link: Physical interface index
17+
* @dev_parent_id: device parent id
18+
* @local: Local address
19+
* @remote: Remote address for tunnels
20+
*/
21+
struct vif_device {
22+
struct net_device *dev;
23+
unsigned long bytes_in, bytes_out;
24+
unsigned long pkt_in, pkt_out;
25+
unsigned long rate_limit;
26+
unsigned char threshold;
27+
unsigned short flags;
28+
int link;
29+
30+
/* Currently only used by ipmr */
31+
struct netdev_phys_item_id dev_parent_id;
32+
__be32 local, remote;
33+
};
34+
35+
#ifdef CONFIG_IP_MROUTE_COMMON
36+
void vif_device_init(struct vif_device *v,
37+
struct net_device *dev,
38+
unsigned long rate_limit,
39+
unsigned char threshold,
40+
unsigned short flags,
41+
unsigned short get_iflink_mask);
42+
#else
43+
static inline void vif_device_init(struct vif_device *v,
44+
struct net_device *dev,
45+
unsigned long rate_limit,
46+
unsigned char threshold,
47+
unsigned short flags,
48+
unsigned short get_iflink_mask)
49+
{
50+
}
51+
#endif
52+
#endif

net/ipv4/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,14 @@ config NET_IPGRE_BROADCAST
212212
Network), but can be distributed all over the Internet. If you want
213213
to do that, say Y here and to "IP multicast routing" below.
214214

215+
config IP_MROUTE_COMMON
216+
bool
217+
depends on IP_MROUTE || IPV6_MROUTE
218+
215219
config IP_MROUTE
216220
bool "IP: multicast routing"
217221
depends on IP_MULTICAST
222+
select IP_MROUTE_COMMON
218223
help
219224
This is used if you want your machine to act as a router for IP
220225
packets that have several destination addresses. It is needed on the

net/ipv4/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
2020
obj-$(CONFIG_PROC_FS) += proc.o
2121
obj-$(CONFIG_IP_MULTIPLE_TABLES) += fib_rules.o
2222
obj-$(CONFIG_IP_MROUTE) += ipmr.o
23+
obj-$(CONFIG_IP_MROUTE_COMMON) += ipmr_base.o
2324
obj-$(CONFIG_NET_IPIP) += ipip.o
2425
gre-y := gre_demux.o
2526
obj-$(CONFIG_NET_FOU) += fou.o

net/ipv4/ipmr.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,10 @@ static int vif_add(struct net *net, struct mr_table *mrt,
945945
ip_rt_multicast_event(in_dev);
946946

947947
/* Fill in the VIF structures */
948+
vif_device_init(v, dev, vifc->vifc_rate_limit,
949+
vifc->vifc_threshold,
950+
vifc->vifc_flags | (!mrtsock ? VIFF_STATIC : 0),
951+
(VIFF_TUNNEL | VIFF_REGISTER));
948952

949953
attr.orig_dev = dev;
950954
if (!switchdev_port_attr_get(dev, &attr)) {
@@ -953,20 +957,9 @@ static int vif_add(struct net *net, struct mr_table *mrt,
953957
} else {
954958
v->dev_parent_id.id_len = 0;
955959
}
956-
v->rate_limit = vifc->vifc_rate_limit;
960+
957961
v->local = vifc->vifc_lcl_addr.s_addr;
958962
v->remote = vifc->vifc_rmt_addr.s_addr;
959-
v->flags = vifc->vifc_flags;
960-
if (!mrtsock)
961-
v->flags |= VIFF_STATIC;
962-
v->threshold = vifc->vifc_threshold;
963-
v->bytes_in = 0;
964-
v->bytes_out = 0;
965-
v->pkt_in = 0;
966-
v->pkt_out = 0;
967-
v->link = dev->ifindex;
968-
if (v->flags & (VIFF_TUNNEL | VIFF_REGISTER))
969-
v->link = dev_get_iflink(dev);
970963

971964
/* And finish update writing critical data */
972965
write_lock_bh(&mrt_lock);
@@ -2316,7 +2309,8 @@ static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
23162309
}
23172310

23182311
if (VIF_EXISTS(mrt, c->mfc_parent) &&
2319-
nla_put_u32(skb, RTA_IIF, mrt->vif_table[c->mfc_parent].dev->ifindex) < 0)
2312+
nla_put_u32(skb, RTA_IIF,
2313+
mrt->vif_table[c->mfc_parent].dev->ifindex) < 0)
23202314
return -EMSGSIZE;
23212315

23222316
if (c->mfc_flags & MFC_OFFLOAD)
@@ -2327,14 +2321,17 @@ static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
23272321

23282322
for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
23292323
if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) {
2324+
struct vif_device *vif;
2325+
23302326
if (!(nhp = nla_reserve_nohdr(skb, sizeof(*nhp)))) {
23312327
nla_nest_cancel(skb, mp_attr);
23322328
return -EMSGSIZE;
23332329
}
23342330

23352331
nhp->rtnh_flags = 0;
23362332
nhp->rtnh_hops = c->mfc_un.res.ttls[ct];
2337-
nhp->rtnh_ifindex = mrt->vif_table[ct].dev->ifindex;
2333+
vif = &mrt->vif_table[ct];
2334+
nhp->rtnh_ifindex = vif->dev->ifindex;
23382335
nhp->rtnh_len = sizeof(*nhp);
23392336
}
23402337
}
@@ -2954,8 +2951,8 @@ struct ipmr_vif_iter {
29542951
};
29552952

29562953
static struct vif_device *ipmr_vif_seq_idx(struct net *net,
2957-
struct ipmr_vif_iter *iter,
2958-
loff_t pos)
2954+
struct ipmr_vif_iter *iter,
2955+
loff_t pos)
29592956
{
29602957
struct mr_table *mrt = iter->mrt;
29612958

@@ -3020,7 +3017,8 @@ static int ipmr_vif_seq_show(struct seq_file *seq, void *v)
30203017
"Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n");
30213018
} else {
30223019
const struct vif_device *vif = v;
3023-
const char *name = vif->dev ? vif->dev->name : "none";
3020+
const char *name = vif->dev ?
3021+
vif->dev->name : "none";
30243022

30253023
seq_printf(seq,
30263024
"%2td %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n",

net/ipv4/ipmr_base.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Linux multicast routing support
2+
* Common logic shared by IPv4 [ipmr] and IPv6 [ip6mr] implementation
3+
*/
4+
5+
#include <linux/mroute_base.h>
6+
7+
/* Sets everything common except 'dev', since that is done under locking */
8+
void vif_device_init(struct vif_device *v,
9+
struct net_device *dev,
10+
unsigned long rate_limit,
11+
unsigned char threshold,
12+
unsigned short flags,
13+
unsigned short get_iflink_mask)
14+
{
15+
v->dev = NULL;
16+
v->bytes_in = 0;
17+
v->bytes_out = 0;
18+
v->pkt_in = 0;
19+
v->pkt_out = 0;
20+
v->rate_limit = rate_limit;
21+
v->flags = flags;
22+
v->threshold = threshold;
23+
if (v->flags & get_iflink_mask)
24+
v->link = dev_get_iflink(dev);
25+
else
26+
v->link = dev->ifindex;
27+
}
28+
EXPORT_SYMBOL(vif_device_init);

net/ipv6/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ config IPV6_SUBTREES
278278
config IPV6_MROUTE
279279
bool "IPv6: multicast routing"
280280
depends on IPV6
281+
select IP_MROUTE_COMMON
281282
---help---
282283
Experimental support for IPv6 multicast forwarding.
283284
If unsure, say N.

net/ipv6/ip6mr.c

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct mr6_table {
6262
struct timer_list ipmr_expire_timer;
6363
struct list_head mfc6_unres_queue;
6464
struct list_head mfc6_cache_array[MFC6_LINES];
65-
struct mif_device vif6_table[MAXMIFS];
65+
struct vif_device vif6_table[MAXMIFS];
6666
int maxvif;
6767
atomic_t cache_resolve_queue_len;
6868
bool mroute_do_assert;
@@ -384,7 +384,7 @@ struct ipmr_vif_iter {
384384
int ct;
385385
};
386386

387-
static struct mif_device *ip6mr_vif_seq_idx(struct net *net,
387+
static struct vif_device *ip6mr_vif_seq_idx(struct net *net,
388388
struct ipmr_vif_iter *iter,
389389
loff_t pos)
390390
{
@@ -450,7 +450,7 @@ static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
450450
seq_puts(seq,
451451
"Interface BytesIn PktsIn BytesOut PktsOut Flags\n");
452452
} else {
453-
const struct mif_device *vif = v;
453+
const struct vif_device *vif = v;
454454
const char *name = vif->dev ? vif->dev->name : "none";
455455

456456
seq_printf(seq,
@@ -776,7 +776,7 @@ static struct net_device *ip6mr_reg_vif(struct net *net, struct mr6_table *mrt)
776776
static int mif6_delete(struct mr6_table *mrt, int vifi, int notify,
777777
struct list_head *head)
778778
{
779-
struct mif_device *v;
779+
struct vif_device *v;
780780
struct net_device *dev;
781781
struct inet6_dev *in6_dev;
782782

@@ -929,7 +929,7 @@ static int mif6_add(struct net *net, struct mr6_table *mrt,
929929
struct mif6ctl *vifc, int mrtsock)
930930
{
931931
int vifi = vifc->mif6c_mifi;
932-
struct mif_device *v = &mrt->vif6_table[vifi];
932+
struct vif_device *v = &mrt->vif6_table[vifi];
933933
struct net_device *dev;
934934
struct inet6_dev *in6_dev;
935935
int err;
@@ -980,21 +980,10 @@ static int mif6_add(struct net *net, struct mr6_table *mrt,
980980
dev->ifindex, &in6_dev->cnf);
981981
}
982982

983-
/*
984-
* Fill in the VIF structures
985-
*/
986-
v->rate_limit = vifc->vifc_rate_limit;
987-
v->flags = vifc->mif6c_flags;
988-
if (!mrtsock)
989-
v->flags |= VIFF_STATIC;
990-
v->threshold = vifc->vifc_threshold;
991-
v->bytes_in = 0;
992-
v->bytes_out = 0;
993-
v->pkt_in = 0;
994-
v->pkt_out = 0;
995-
v->link = dev->ifindex;
996-
if (v->flags & MIFF_REGISTER)
997-
v->link = dev_get_iflink(dev);
983+
/* Fill in the VIF structures */
984+
vif_device_init(v, dev, vifc->vifc_rate_limit, vifc->vifc_threshold,
985+
vifc->mif6c_flags | (!mrtsock ? VIFF_STATIC : 0),
986+
MIFF_REGISTER);
998987

999988
/* And finish update writing critical data */
1000989
write_lock_bh(&mrt_lock);
@@ -1332,7 +1321,7 @@ static int ip6mr_device_event(struct notifier_block *this,
13321321
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
13331322
struct net *net = dev_net(dev);
13341323
struct mr6_table *mrt;
1335-
struct mif_device *v;
1324+
struct vif_device *v;
13361325
int ct;
13371326

13381327
if (event != NETDEV_UNREGISTER)
@@ -1873,7 +1862,7 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
18731862
{
18741863
struct sioc_sg_req6 sr;
18751864
struct sioc_mif_req6 vr;
1876-
struct mif_device *vif;
1865+
struct vif_device *vif;
18771866
struct mfc6_cache *c;
18781867
struct net *net = sock_net(sk);
18791868
struct mr6_table *mrt;
@@ -1947,7 +1936,7 @@ int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg)
19471936
{
19481937
struct compat_sioc_sg_req6 sr;
19491938
struct compat_sioc_mif_req6 vr;
1950-
struct mif_device *vif;
1939+
struct vif_device *vif;
19511940
struct mfc6_cache *c;
19521941
struct net *net = sock_net(sk);
19531942
struct mr6_table *mrt;
@@ -2018,7 +2007,7 @@ static int ip6mr_forward2(struct net *net, struct mr6_table *mrt,
20182007
struct sk_buff *skb, struct mfc6_cache *c, int vifi)
20192008
{
20202009
struct ipv6hdr *ipv6h;
2021-
struct mif_device *vif = &mrt->vif6_table[vifi];
2010+
struct vif_device *vif = &mrt->vif6_table[vifi];
20222011
struct net_device *dev;
20232012
struct dst_entry *dst;
20242013
struct flowi6 fl6;

0 commit comments

Comments
 (0)