bonding: send IPv6 neighbor advertisement on failover
[deliverable/linux.git] / drivers / net / bonding / bond_ipv6.c
1 /*
2 * Copyright(c) 2008 Hewlett-Packard Development Company, L.P.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 */
22
23 //#define BONDING_DEBUG 1
24
25 #include <linux/types.h>
26 #include <linux/if_vlan.h>
27 #include <net/ipv6.h>
28 #include <net/ndisc.h>
29 #include <net/addrconf.h>
30 #include "bonding.h"
31
32 /*
33 * Assign bond->master_ipv6 to the next IPv6 address in the list, or
34 * zero it out if there are none.
35 */
36 static void bond_glean_dev_ipv6(struct net_device *dev, struct in6_addr *addr)
37 {
38 struct inet6_dev *idev;
39 struct inet6_ifaddr *ifa;
40
41 if (!dev)
42 return;
43
44 idev = in6_dev_get(dev);
45 if (!idev)
46 return;
47
48 read_lock_bh(&idev->lock);
49 ifa = idev->addr_list;
50 if (ifa)
51 ipv6_addr_copy(addr, &ifa->addr);
52 else
53 ipv6_addr_set(addr, 0, 0, 0, 0);
54
55 read_unlock_bh(&idev->lock);
56
57 in6_dev_put(idev);
58 }
59
60 static void bond_na_send(struct net_device *slave_dev,
61 struct in6_addr *daddr,
62 int router,
63 unsigned short vlan_id)
64 {
65 struct in6_addr mcaddr;
66 struct icmp6hdr icmp6h = {
67 .icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT,
68 };
69 struct sk_buff *skb;
70
71 icmp6h.icmp6_router = router;
72 icmp6h.icmp6_solicited = 0;
73 icmp6h.icmp6_override = 1;
74
75 addrconf_addr_solict_mult(daddr, &mcaddr);
76
77 dprintk("ipv6 na on slave %s: dest %pI6, src %pI6\n",
78 slave->name, &mcaddr, daddr);
79
80 skb = ndisc_build_skb(slave_dev, &mcaddr, daddr, &icmp6h, daddr,
81 ND_OPT_TARGET_LL_ADDR);
82
83 if (!skb) {
84 printk(KERN_ERR DRV_NAME ": NA packet allocation failed\n");
85 return;
86 }
87
88 if (vlan_id) {
89 skb = vlan_put_tag(skb, vlan_id);
90 if (!skb) {
91 printk(KERN_ERR DRV_NAME ": failed to insert VLAN tag\n");
92 return;
93 }
94 }
95
96 ndisc_send_skb(skb, slave_dev, NULL, &mcaddr, daddr, &icmp6h);
97 }
98
99 /*
100 * Kick out an unsolicited Neighbor Advertisement for an IPv6 address on
101 * the bonding master. This will help the switch learn our address
102 * if in active-backup mode.
103 *
104 * Caller must hold curr_slave_lock for read or better
105 */
106 void bond_send_unsolicited_na(struct bonding *bond)
107 {
108 struct slave *slave = bond->curr_active_slave;
109 struct vlan_entry *vlan;
110 struct inet6_dev *idev;
111 int is_router;
112
113 dprintk("bond_send_unsol_na: bond %s slave %s\n", bond->dev->name,
114 slave ? slave->dev->name : "NULL");
115
116 if (!slave || !bond->send_unsol_na ||
117 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
118 return;
119
120 bond->send_unsol_na--;
121
122 idev = in6_dev_get(bond->dev);
123 if (!idev)
124 return;
125
126 is_router = !!idev->cnf.forwarding;
127
128 in6_dev_put(idev);
129
130 if (!ipv6_addr_any(&bond->master_ipv6))
131 bond_na_send(slave->dev, &bond->master_ipv6, is_router, 0);
132
133 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
134 if (!ipv6_addr_any(&vlan->vlan_ipv6)) {
135 bond_na_send(slave->dev, &vlan->vlan_ipv6, is_router,
136 vlan->vlan_id);
137 }
138 }
139 }
140
141 /*
142 * bond_inet6addr_event: handle inet6addr notifier chain events.
143 *
144 * We keep track of device IPv6 addresses primarily to use as source
145 * addresses in NS probes.
146 *
147 * We track one IPv6 for the main device (if it has one).
148 */
149 static int bond_inet6addr_event(struct notifier_block *this,
150 unsigned long event,
151 void *ptr)
152 {
153 struct inet6_ifaddr *ifa = ptr;
154 struct net_device *vlan_dev, *event_dev = ifa->idev->dev;
155 struct bonding *bond;
156 struct vlan_entry *vlan;
157
158 if (dev_net(event_dev) != &init_net)
159 return NOTIFY_DONE;
160
161 list_for_each_entry(bond, &bond_dev_list, bond_list) {
162 if (bond->dev == event_dev) {
163 switch (event) {
164 case NETDEV_UP:
165 if (ipv6_addr_any(&bond->master_ipv6))
166 ipv6_addr_copy(&bond->master_ipv6,
167 &ifa->addr);
168 return NOTIFY_OK;
169 case NETDEV_DOWN:
170 if (ipv6_addr_equal(&bond->master_ipv6,
171 &ifa->addr))
172 bond_glean_dev_ipv6(bond->dev,
173 &bond->master_ipv6);
174 return NOTIFY_OK;
175 default:
176 return NOTIFY_DONE;
177 }
178 }
179
180 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
181 vlan_dev = vlan_group_get_device(bond->vlgrp,
182 vlan->vlan_id);
183 if (vlan_dev == event_dev) {
184 switch (event) {
185 case NETDEV_UP:
186 if (ipv6_addr_any(&vlan->vlan_ipv6))
187 ipv6_addr_copy(&vlan->vlan_ipv6,
188 &ifa->addr);
189 return NOTIFY_OK;
190 case NETDEV_DOWN:
191 if (ipv6_addr_equal(&vlan->vlan_ipv6,
192 &ifa->addr))
193 bond_glean_dev_ipv6(vlan_dev,
194 &vlan->vlan_ipv6);
195 return NOTIFY_OK;
196 default:
197 return NOTIFY_DONE;
198 }
199 }
200 }
201 }
202 return NOTIFY_DONE;
203 }
204
205 static struct notifier_block bond_inet6addr_notifier = {
206 .notifier_call = bond_inet6addr_event,
207 };
208
209 void bond_register_ipv6_notifier(void)
210 {
211 register_inet6addr_notifier(&bond_inet6addr_notifier);
212 }
213
214 void bond_unregister_ipv6_notifier(void)
215 {
216 unregister_inet6addr_notifier(&bond_inet6addr_notifier);
217 }
218
This page took 0.035434 seconds and 5 git commands to generate.