Skip to content

Commit e0835f8

Browse files
committed
ipv4,ipv6 mroute: Add some helper inline functions to remove ugly ifdefs.
ip{,v6}_mroute_{set,get}sockopt() should not matter by optimization but it would be better not to depend on optimization semantically. Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
1 parent 03d2f89 commit e0835f8

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

include/linux/mroute.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,37 @@ static inline int ip_mroute_opt(int opt)
144144
}
145145
#endif
146146

147+
#ifdef CONFIG_IP_MROUTE
147148
extern int ip_mroute_setsockopt(struct sock *, int, char __user *, int);
148149
extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
149150
extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
150151
extern int ip_mr_init(void);
152+
#else
153+
static inline
154+
int ip_mroute_setsockopt(struct sock *sock,
155+
int optname, char __user *optval, int optlen)
156+
{
157+
return -ENOPROTOOPT;
158+
}
159+
160+
static inline
161+
int ip_mroute_getsockopt(struct sock *sock,
162+
int optname, char __user *optval, int __user *optlen)
163+
{
164+
return -ENOPROTOOPT;
165+
}
166+
167+
static inline
168+
int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
169+
{
170+
return -ENOIOCTLCMD;
171+
}
172+
173+
static inline int ip_mr_init(void)
174+
{
175+
return 0;
176+
}
177+
#endif
151178

152179
struct vif_device
153180
{

include/linux/mroute6.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,44 @@ static inline int ip6_mroute_opt(int opt)
131131

132132
struct sock;
133133

134+
#ifdef CONFIG_IPV6_MROUTE
134135
extern int ip6_mroute_setsockopt(struct sock *, int, char __user *, int);
135136
extern int ip6_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
136137
extern int ip6_mr_input(struct sk_buff *skb);
137138
extern int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg);
138139
extern int ip6_mr_init(void);
139140
extern void ip6_mr_cleanup(void);
141+
#else
142+
static inline
143+
int ip6_mroute_setsockopt(struct sock *sock,
144+
int optname, char __user *optval, int optlen)
145+
{
146+
return -ENOPROTOOPT;
147+
}
148+
149+
static inline
150+
int ip6_mroute_getsockopt(struct sock *sock,
151+
int optname, char __user *optval, int __user *optlen)
152+
{
153+
return -ENOPROTOOPT;
154+
}
155+
156+
static inline
157+
int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
158+
{
159+
return -ENOIOCTLCMD;
160+
}
161+
162+
static inline int ip6_mr_init(void)
163+
{
164+
return 0;
165+
}
166+
167+
static inline void ip6_mr_cleanup(void)
168+
{
169+
return;
170+
}
171+
#endif
140172

141173
struct mif_device
142174
{

net/ipv6/af_inet6.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@
5959

6060
#include <asm/uaccess.h>
6161
#include <asm/system.h>
62-
#ifdef CONFIG_IPV6_MROUTE
6362
#include <linux/mroute6.h>
64-
#endif
6563

6664
MODULE_AUTHOR("Cast of dozens");
6765
MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
@@ -952,11 +950,9 @@ static int __init inet6_init(void)
952950
err = icmpv6_init();
953951
if (err)
954952
goto icmp_fail;
955-
#ifdef CONFIG_IPV6_MROUTE
956953
err = ip6_mr_init();
957954
if (err)
958955
goto ipmr_fail;
959-
#endif
960956
err = ndisc_init();
961957
if (err)
962958
goto ndisc_fail;
@@ -1059,10 +1055,8 @@ static int __init inet6_init(void)
10591055
igmp_fail:
10601056
ndisc_cleanup();
10611057
ndisc_fail:
1062-
#ifdef CONFIG_IPV6_MROUTE
10631058
ip6_mr_cleanup();
10641059
ipmr_fail:
1065-
#endif
10661060
icmpv6_cleanup();
10671061
icmp_fail:
10681062
unregister_pernet_subsys(&inet6_net_ops);
@@ -1117,9 +1111,7 @@ static void __exit inet6_exit(void)
11171111
ipv6_netfilter_fini();
11181112
igmp6_cleanup();
11191113
ndisc_cleanup();
1120-
#ifdef CONFIG_IPV6_MROUTE
11211114
ip6_mr_cleanup();
1122-
#endif
11231115
icmpv6_cleanup();
11241116
rawv6_exit();
11251117

0 commit comments

Comments
 (0)