blob: b72e1dc8cf8fc9cf7722e093ad51900bdfc253db [file] [log] [blame]
Brian Haley305d5522008-11-04 17:51:14 -08001/*
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
Brian Haley305d5522008-11-04 17:51:14 -080023#include <linux/types.h>
24#include <linux/if_vlan.h>
25#include <net/ipv6.h>
26#include <net/ndisc.h>
27#include <net/addrconf.h>
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000028#include <net/netns/generic.h>
Brian Haley305d5522008-11-04 17:51:14 -080029#include "bonding.h"
30
31/*
32 * Assign bond->master_ipv6 to the next IPv6 address in the list, or
33 * zero it out if there are none.
34 */
35static void bond_glean_dev_ipv6(struct net_device *dev, struct in6_addr *addr)
36{
37 struct inet6_dev *idev;
38 struct inet6_ifaddr *ifa;
39
40 if (!dev)
41 return;
42
43 idev = in6_dev_get(dev);
44 if (!idev)
45 return;
46
47 read_lock_bh(&idev->lock);
48 ifa = idev->addr_list;
49 if (ifa)
50 ipv6_addr_copy(addr, &ifa->addr);
51 else
52 ipv6_addr_set(addr, 0, 0, 0, 0);
53
54 read_unlock_bh(&idev->lock);
55
56 in6_dev_put(idev);
57}
58
59static void bond_na_send(struct net_device *slave_dev,
60 struct in6_addr *daddr,
61 int router,
62 unsigned short vlan_id)
63{
64 struct in6_addr mcaddr;
65 struct icmp6hdr icmp6h = {
66 .icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT,
67 };
68 struct sk_buff *skb;
69
70 icmp6h.icmp6_router = router;
71 icmp6h.icmp6_solicited = 0;
72 icmp6h.icmp6_override = 1;
73
74 addrconf_addr_solict_mult(daddr, &mcaddr);
75
Holger Eitzenberger5a03cdb2008-12-09 23:09:22 -080076 pr_debug("ipv6 na on slave %s: dest %pI6, src %pI6\n",
Holger Eitzenbergeref655832008-12-09 23:08:55 -080077 slave_dev->name, &mcaddr, daddr);
Brian Haley305d5522008-11-04 17:51:14 -080078
79 skb = ndisc_build_skb(slave_dev, &mcaddr, daddr, &icmp6h, daddr,
80 ND_OPT_TARGET_LL_ADDR);
81
82 if (!skb) {
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +000083 pr_err(DRV_NAME ": NA packet allocation failed\n");
Brian Haley305d5522008-11-04 17:51:14 -080084 return;
85 }
86
87 if (vlan_id) {
88 skb = vlan_put_tag(skb, vlan_id);
89 if (!skb) {
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +000090 pr_err(DRV_NAME ": failed to insert VLAN tag\n");
Brian Haley305d5522008-11-04 17:51:14 -080091 return;
92 }
93 }
94
95 ndisc_send_skb(skb, slave_dev, NULL, &mcaddr, daddr, &icmp6h);
96}
97
98/*
99 * Kick out an unsolicited Neighbor Advertisement for an IPv6 address on
100 * the bonding master. This will help the switch learn our address
101 * if in active-backup mode.
102 *
103 * Caller must hold curr_slave_lock for read or better
104 */
105void bond_send_unsolicited_na(struct bonding *bond)
106{
107 struct slave *slave = bond->curr_active_slave;
108 struct vlan_entry *vlan;
109 struct inet6_dev *idev;
110 int is_router;
111
Holger Eitzenberger5a03cdb2008-12-09 23:09:22 -0800112 pr_debug("bond_send_unsol_na: bond %s slave %s\n", bond->dev->name,
Brian Haley305d5522008-11-04 17:51:14 -0800113 slave ? slave->dev->name : "NULL");
114
115 if (!slave || !bond->send_unsol_na ||
116 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
117 return;
118
119 bond->send_unsol_na--;
120
121 idev = in6_dev_get(bond->dev);
122 if (!idev)
123 return;
124
125 is_router = !!idev->cnf.forwarding;
126
127 in6_dev_put(idev);
128
129 if (!ipv6_addr_any(&bond->master_ipv6))
130 bond_na_send(slave->dev, &bond->master_ipv6, is_router, 0);
131
132 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
133 if (!ipv6_addr_any(&vlan->vlan_ipv6)) {
134 bond_na_send(slave->dev, &vlan->vlan_ipv6, is_router,
135 vlan->vlan_id);
136 }
137 }
138}
139
140/*
141 * bond_inet6addr_event: handle inet6addr notifier chain events.
142 *
143 * We keep track of device IPv6 addresses primarily to use as source
144 * addresses in NS probes.
145 *
146 * We track one IPv6 for the main device (if it has one).
147 */
148static int bond_inet6addr_event(struct notifier_block *this,
149 unsigned long event,
150 void *ptr)
151{
152 struct inet6_ifaddr *ifa = ptr;
153 struct net_device *vlan_dev, *event_dev = ifa->idev->dev;
154 struct bonding *bond;
155 struct vlan_entry *vlan;
Eric W. Biedermanec87fd32009-10-29 14:18:26 +0000156 struct bond_net *bn = net_generic(dev_net(event_dev), bond_net_id);
Brian Haley305d5522008-11-04 17:51:14 -0800157
Eric W. Biedermanec87fd32009-10-29 14:18:26 +0000158 list_for_each_entry(bond, &bn->dev_list, bond_list) {
Brian Haley305d5522008-11-04 17:51:14 -0800159 if (bond->dev == event_dev) {
160 switch (event) {
161 case NETDEV_UP:
162 if (ipv6_addr_any(&bond->master_ipv6))
163 ipv6_addr_copy(&bond->master_ipv6,
164 &ifa->addr);
165 return NOTIFY_OK;
166 case NETDEV_DOWN:
167 if (ipv6_addr_equal(&bond->master_ipv6,
168 &ifa->addr))
169 bond_glean_dev_ipv6(bond->dev,
170 &bond->master_ipv6);
171 return NOTIFY_OK;
172 default:
173 return NOTIFY_DONE;
174 }
175 }
176
177 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
178 vlan_dev = vlan_group_get_device(bond->vlgrp,
179 vlan->vlan_id);
180 if (vlan_dev == event_dev) {
181 switch (event) {
182 case NETDEV_UP:
183 if (ipv6_addr_any(&vlan->vlan_ipv6))
184 ipv6_addr_copy(&vlan->vlan_ipv6,
185 &ifa->addr);
186 return NOTIFY_OK;
187 case NETDEV_DOWN:
188 if (ipv6_addr_equal(&vlan->vlan_ipv6,
189 &ifa->addr))
190 bond_glean_dev_ipv6(vlan_dev,
191 &vlan->vlan_ipv6);
192 return NOTIFY_OK;
193 default:
194 return NOTIFY_DONE;
195 }
196 }
197 }
198 }
199 return NOTIFY_DONE;
200}
201
202static struct notifier_block bond_inet6addr_notifier = {
203 .notifier_call = bond_inet6addr_event,
204};
205
206void bond_register_ipv6_notifier(void)
207{
208 register_inet6addr_notifier(&bond_inet6addr_notifier);
209}
210
211void bond_unregister_ipv6_notifier(void)
212{
213 unregister_inet6addr_notifier(&bond_inet6addr_notifier);
214}
215