USB: serial: ftdi_sio: adding support for TavIR STK500
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / bonding / bond_ipv6.c
blob642a3b9d81ff877a54dfb56f496684abde38a167
1 /*
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
12 * for more details.
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 #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>
28 #include "bonding.h"
31 * Assign bond->master_ipv6 to the next IPv6 address in the list, or
32 * zero it out if there are none.
34 static void bond_glean_dev_ipv6(struct net_device *dev, struct in6_addr *addr)
36 struct inet6_dev *idev;
37 struct inet6_ifaddr *ifa;
39 if (!dev)
40 return;
42 idev = in6_dev_get(dev);
43 if (!idev)
44 return;
46 read_lock_bh(&idev->lock);
47 ifa = idev->addr_list;
48 if (ifa)
49 ipv6_addr_copy(addr, &ifa->addr);
50 else
51 ipv6_addr_set(addr, 0, 0, 0, 0);
53 read_unlock_bh(&idev->lock);
55 in6_dev_put(idev);
58 static void bond_na_send(struct net_device *slave_dev,
59 struct in6_addr *daddr,
60 int router,
61 unsigned short vlan_id)
63 struct in6_addr mcaddr;
64 struct icmp6hdr icmp6h = {
65 .icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT,
67 struct sk_buff *skb;
69 /* The Ethernet header is built in ndisc_send_skb(), not
70 * ndisc_build_skb(), so we cannot insert a VLAN tag. Only an
71 * out-of-line tag inserted by the hardware will work.
73 if (vlan_id && !(slave_dev->features & NETIF_F_HW_VLAN_TX))
74 return;
76 icmp6h.icmp6_router = router;
77 icmp6h.icmp6_solicited = 0;
78 icmp6h.icmp6_override = 1;
80 addrconf_addr_solict_mult(daddr, &mcaddr);
82 pr_debug("ipv6 na on slave %s: dest %pI6, src %pI6\n",
83 slave_dev->name, &mcaddr, daddr);
85 skb = ndisc_build_skb(slave_dev, &mcaddr, daddr, &icmp6h, daddr,
86 ND_OPT_TARGET_LL_ADDR);
88 if (!skb) {
89 pr_err(DRV_NAME ": NA packet allocation failed\n");
90 return;
93 if (vlan_id) {
94 skb = __vlan_hwaccel_put_tag(skb, vlan_id);
95 if (!skb) {
96 pr_err(DRV_NAME ": failed to insert VLAN tag\n");
97 return;
101 ndisc_send_skb(skb, slave_dev, NULL, &mcaddr, daddr, &icmp6h);
105 * Kick out an unsolicited Neighbor Advertisement for an IPv6 address on
106 * the bonding master. This will help the switch learn our address
107 * if in active-backup mode.
109 * Caller must hold curr_slave_lock for read or better
111 void bond_send_unsolicited_na(struct bonding *bond)
113 struct slave *slave = bond->curr_active_slave;
114 struct vlan_entry *vlan;
115 struct inet6_dev *idev;
116 int is_router;
118 pr_debug("bond_send_unsol_na: bond %s slave %s\n", bond->dev->name,
119 slave ? slave->dev->name : "NULL");
121 if (!slave || !bond->send_unsol_na ||
122 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
123 return;
125 bond->send_unsol_na--;
127 idev = in6_dev_get(bond->dev);
128 if (!idev)
129 return;
131 is_router = !!idev->cnf.forwarding;
133 in6_dev_put(idev);
135 if (!ipv6_addr_any(&bond->master_ipv6))
136 bond_na_send(slave->dev, &bond->master_ipv6, is_router, 0);
138 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
139 if (!ipv6_addr_any(&vlan->vlan_ipv6)) {
140 bond_na_send(slave->dev, &vlan->vlan_ipv6, is_router,
141 vlan->vlan_id);
147 * bond_inet6addr_event: handle inet6addr notifier chain events.
149 * We keep track of device IPv6 addresses primarily to use as source
150 * addresses in NS probes.
152 * We track one IPv6 for the main device (if it has one).
154 static int bond_inet6addr_event(struct notifier_block *this,
155 unsigned long event,
156 void *ptr)
158 struct inet6_ifaddr *ifa = ptr;
159 struct net_device *vlan_dev, *event_dev = ifa->idev->dev;
160 struct bonding *bond;
161 struct vlan_entry *vlan;
163 if (dev_net(event_dev) != &init_net)
164 return NOTIFY_DONE;
166 list_for_each_entry(bond, &bond_dev_list, bond_list) {
167 if (bond->dev == event_dev) {
168 switch (event) {
169 case NETDEV_UP:
170 if (ipv6_addr_any(&bond->master_ipv6))
171 ipv6_addr_copy(&bond->master_ipv6,
172 &ifa->addr);
173 return NOTIFY_OK;
174 case NETDEV_DOWN:
175 if (ipv6_addr_equal(&bond->master_ipv6,
176 &ifa->addr))
177 bond_glean_dev_ipv6(bond->dev,
178 &bond->master_ipv6);
179 return NOTIFY_OK;
180 default:
181 return NOTIFY_DONE;
185 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
186 vlan_dev = vlan_group_get_device(bond->vlgrp,
187 vlan->vlan_id);
188 if (vlan_dev == event_dev) {
189 switch (event) {
190 case NETDEV_UP:
191 if (ipv6_addr_any(&vlan->vlan_ipv6))
192 ipv6_addr_copy(&vlan->vlan_ipv6,
193 &ifa->addr);
194 return NOTIFY_OK;
195 case NETDEV_DOWN:
196 if (ipv6_addr_equal(&vlan->vlan_ipv6,
197 &ifa->addr))
198 bond_glean_dev_ipv6(vlan_dev,
199 &vlan->vlan_ipv6);
200 return NOTIFY_OK;
201 default:
202 return NOTIFY_DONE;
207 return NOTIFY_DONE;
210 static struct notifier_block bond_inet6addr_notifier = {
211 .notifier_call = bond_inet6addr_event,
214 void bond_register_ipv6_notifier(void)
216 register_inet6addr_notifier(&bond_inet6addr_notifier);
219 void bond_unregister_ipv6_notifier(void)
221 unregister_inet6addr_notifier(&bond_inet6addr_notifier);