Skip to content

Commit 778d80b

Browse files
committed
ipv6: Add disable_ipv6 sysctl to disable IPv6 operaion on specific interface.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
1 parent 5ce83af commit 778d80b

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

Documentation/networking/ip-sysctl.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,10 @@ max_addresses - INTEGER
10251025
autoconfigured addresses.
10261026
Default: 16
10271027

1028+
disable_ipv6 - BOOLEAN
1029+
Disable IPv6 operation.
1030+
Default: FALSE (enable IPv6 operation)
1031+
10281032
icmp/*:
10291033
ratelimit - INTEGER
10301034
Limit the maximal rates for sending ICMPv6 packets.

include/linux/ipv6.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ struct ipv6_devconf {
163163
#ifdef CONFIG_IPV6_MROUTE
164164
__s32 mc_forwarding;
165165
#endif
166+
__s32 disable_ipv6;
166167
void *sysctl;
167168
};
168169

@@ -194,6 +195,7 @@ enum {
194195
DEVCONF_OPTIMISTIC_DAD,
195196
DEVCONF_ACCEPT_SOURCE_ROUTE,
196197
DEVCONF_MC_FORWARDING,
198+
DEVCONF_DISABLE_IPV6,
197199
DEVCONF_MAX
198200
};
199201

net/ipv6/addrconf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct ipv6_devconf ipv6_devconf __read_mostly = {
183183
#endif
184184
.proxy_ndp = 0,
185185
.accept_source_route = 0, /* we do not accept RH0 by default. */
186+
.disable_ipv6 = 0,
186187
};
187188

188189
static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
@@ -215,6 +216,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
215216
#endif
216217
.proxy_ndp = 0,
217218
.accept_source_route = 0, /* we do not accept RH0 by default. */
219+
.disable_ipv6 = 0,
218220
};
219221

220222
/* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
@@ -3657,6 +3659,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
36573659
#ifdef CONFIG_IPV6_MROUTE
36583660
array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding;
36593661
#endif
3662+
array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6;
36603663
}
36613664

36623665
static inline size_t inet6_if_nlmsg_size(void)
@@ -4215,6 +4218,14 @@ static struct addrconf_sysctl_table
42154218
.proc_handler = &proc_dointvec,
42164219
},
42174220
#endif
4221+
{
4222+
.ctl_name = CTL_UNNUMBERED,
4223+
.procname = "disable_ipv6",
4224+
.data = &ipv6_devconf.disable_ipv6,
4225+
.maxlen = sizeof(int),
4226+
.mode = 0644,
4227+
.proc_handler = &proc_dointvec,
4228+
},
42184229
{
42194230
.ctl_name = 0, /* sentinel */
42204231
}

net/ipv6/ip6_input.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
7171

7272
IP6_INC_STATS_BH(idev, IPSTATS_MIB_INRECEIVES);
7373

74-
if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
74+
if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL ||
75+
!idev || unlikely(idev->cnf.disable_ipv6)) {
7576
IP6_INC_STATS_BH(idev, IPSTATS_MIB_INDISCARDS);
7677
rcu_read_unlock();
7778
goto out;

net/ipv6/ip6_output.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ static inline int ip6_skb_dst_mtu(struct sk_buff *skb)
173173

174174
int ip6_output(struct sk_buff *skb)
175175
{
176+
struct inet6_dev *idev = ip6_dst_idev(skb->dst);
177+
if (unlikely(idev->cnf.disable_ipv6)) {
178+
IP6_INC_STATS(idev, IPSTATS_MIB_OUTDISCARDS);
179+
kfree_skb(skb);
180+
return 0;
181+
}
182+
176183
if ((skb->len > ip6_skb_dst_mtu(skb) && !skb_is_gso(skb)) ||
177184
dst_allfrag(skb->dst))
178185
return ip6_fragment(skb, ip6_output2);

0 commit comments

Comments
 (0)