2 * Copyright(c) 2008 Hewlett-Packard Development Company, L.P.
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.
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
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.
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
23 //#define BONDING_DEBUG 1
25 #include <linux/types.h>
26 #include <linux/if_vlan.h>
28 #include <net/ndisc.h>
29 #include <net/addrconf.h>
33 * Assign bond->master_ipv6 to the next IPv6 address in the list, or
34 * zero it out if there are none.
36 static void bond_glean_dev_ipv6(struct net_device *dev, struct in6_addr *addr)
38 struct inet6_dev *idev;
39 struct inet6_ifaddr *ifa;
44 idev = in6_dev_get(dev);
48 read_lock_bh(&idev->lock);
49 ifa = idev->addr_list;
51 ipv6_addr_copy(addr, &ifa->addr);
53 ipv6_addr_set(addr, 0, 0, 0, 0);
55 read_unlock_bh(&idev->lock);
60 static void bond_na_send(struct net_device *slave_dev,
61 struct in6_addr *daddr,
63 unsigned short vlan_id)
65 struct in6_addr mcaddr;
66 struct icmp6hdr icmp6h = {
67 .icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT,
71 icmp6h.icmp6_router = router;
72 icmp6h.icmp6_solicited = 0;
73 icmp6h.icmp6_override = 1;
75 addrconf_addr_solict_mult(daddr, &mcaddr);
77 dprintk("ipv6 na on slave %s: dest %pI6, src %pI6\n",
78 slave->name, &mcaddr, daddr);
80 skb = ndisc_build_skb(slave_dev, &mcaddr, daddr, &icmp6h, daddr,
81 ND_OPT_TARGET_LL_ADDR);
84 printk(KERN_ERR DRV_NAME ": NA packet allocation failed\n");
89 skb = vlan_put_tag(skb, vlan_id);
91 printk(KERN_ERR DRV_NAME ": failed to insert VLAN tag\n");
96 ndisc_send_skb(skb, slave_dev, NULL, &mcaddr, daddr, &icmp6h);
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.
104 * Caller must hold curr_slave_lock for read or better
106 void bond_send_unsolicited_na(struct bonding *bond)
108 struct slave *slave = bond->curr_active_slave;
109 struct vlan_entry *vlan;
110 struct inet6_dev *idev;
113 dprintk("bond_send_unsol_na: bond %s slave %s\n", bond->dev->name,
114 slave ? slave->dev->name : "NULL");
116 if (!slave || !bond->send_unsol_na ||
117 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
120 bond->send_unsol_na--;
122 idev = in6_dev_get(bond->dev);
126 is_router = !!idev->cnf.forwarding;
130 if (!ipv6_addr_any(&bond->master_ipv6))
131 bond_na_send(slave->dev, &bond->master_ipv6, is_router, 0);
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,
142 * bond_inet6addr_event: handle inet6addr notifier chain events.
144 * We keep track of device IPv6 addresses primarily to use as source
145 * addresses in NS probes.
147 * We track one IPv6 for the main device (if it has one).
149 static int bond_inet6addr_event(struct notifier_block *this,
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;
158 if (dev_net(event_dev) != &init_net)
161 list_for_each_entry(bond, &bond_dev_list, bond_list) {
162 if (bond->dev == event_dev) {
165 if (ipv6_addr_any(&bond->master_ipv6))
166 ipv6_addr_copy(&bond->master_ipv6,
170 if (ipv6_addr_equal(&bond->master_ipv6,
172 bond_glean_dev_ipv6(bond->dev,
180 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
181 vlan_dev = vlan_group_get_device(bond->vlgrp,
183 if (vlan_dev == event_dev) {
186 if (ipv6_addr_any(&vlan->vlan_ipv6))
187 ipv6_addr_copy(&vlan->vlan_ipv6,
191 if (ipv6_addr_equal(&vlan->vlan_ipv6,
193 bond_glean_dev_ipv6(vlan_dev,
205 static struct notifier_block bond_inet6addr_notifier = {
206 .notifier_call = bond_inet6addr_event,
209 void bond_register_ipv6_notifier(void)
211 register_inet6addr_notifier(&bond_inet6addr_notifier);
214 void bond_unregister_ipv6_notifier(void)
216 unregister_inet6addr_notifier(&bond_inet6addr_notifier);