7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
9 #include <linux/slab.h>
10 #include <linux/kernel.h>
11 #include <linux/bitops.h>
12 #include <linux/capability.h>
15 #include <linux/if_ether.h>
16 #include <linux/netdevice.h>
21 #include <asm/byteorder.h>
30 #include <linux/atmdev.h>
34 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
35 #include "../bridge/br_private.h"
37 static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
41 #include <linux/module.h>
48 #define DUMP_PACKETS 0
54 #define LEC_UNRES_QUE_LEN 8
72 static int lane2_associate_req(
struct net_device *
dev,
const u8 *lan_dst,
76 unsigned long permanent);
82 const unsigned char *mac_to_find,
86 const unsigned char *atm_addr,
87 unsigned long remoteflag,
88 unsigned int targetless_le_arp);
89 static void lec_flush_complete(
struct lec_priv *
priv,
unsigned long tran_id);
92 const unsigned char *atm_addr,
93 unsigned long tran_id);
97 void (*old_push)(
struct atm_vcc *vcc,
119 static unsigned char bus_mac[
ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
124 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
135 buff = skb->
data + skb->
dev->hard_header_len;
136 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
151 priv = netdev_priv(dev);
153 sk = sk_atm(priv->
lecd);
171 netif_start_queue(dev);
185 if (vcc->
send(vcc, skb) < 0) {
186 dev->
stats.tx_dropped++;
190 dev->
stats.tx_packets++;
194 static void lec_tx_timeout(
struct net_device *dev)
198 netif_wake_queue(dev);
205 struct lec_priv *priv = netdev_priv(dev);
216 dev->
stats.tx_errors++;
217 netif_stop_queue(dev);
222 pr_debug(
"skbuff head:%lx data:%lx tail:%lx end:%lx\n",
223 (
long)skb->
head, (
long)skb->
data, (
long)skb_tail_pointer(skb),
224 (
long)skb_end_pointer(skb));
225 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
226 if (
memcmp(skb->
data, bridge_ula_lec,
sizeof(bridge_ula_lec)) == 0)
227 lec_handle_bridge(skb, dev);
231 if (skb_headroom(skb) < 2) {
247 #if DUMP_PACKETS >= 2
248 #define MAX_DUMP_SKB 99
249 #elif DUMP_PACKETS >= 1
250 #define MAX_DUMP_SKB 30
252 #if DUMP_PACKETS >= 1
256 skb->
data,
min(skb->
len, MAX_DUMP_SKB),
true);
261 if (skb->
len < min_frame_size) {
262 if ((skb->
len + skb_tailroom(skb)) < min_frame_size) {
268 dev->
stats.tx_dropped++;
280 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
281 pr_debug(
"%s:vcc:%p vcc_flags:%lx, entry:%p\n",
282 dev->
name, vcc, vcc ? vcc->
flags : 0, entry);
285 pr_debug(
"%s:queuing packet, MAC address %pM\n",
289 pr_debug(
"%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
291 dev->
stats.tx_dropped++;
308 if (!atm_may_send(vcc, 0)) {
312 netif_stop_queue(dev);
320 if (atm_may_send(vcc, 0))
321 netif_wake_queue(dev);
334 netif_stop_queue(dev);
342 struct lec_priv *priv = netdev_priv(dev);
353 switch (mesg->
type) {
355 for (i = 0; i < 6; i++)
359 for (i = 0; i < 6; i++)
375 lec_arp_remove(priv, entry);
388 pr_debug(
"LANE2 3.1.5, got tlvs, size %d\n",
414 pr_info(
"%s: change_mtu to %d failed\n",
427 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
429 pr_debug(
"%s: bridge zeppelin asks about %pM\n",
432 if (br_fdb_test_addr_hook ==
NULL)
435 if (br_fdb_test_addr_hook(dev, mesg->
content.
proxy.mac_addr)) {
440 pr_debug(
"%s: entry found, responding to zeppelin\n",
446 skb_copy_to_linear_data(skb2, mesg,
sizeof(*mesg));
448 sk = sk_atm(priv->
lecd);
464 static void lec_atm_close(
struct atm_vcc *vcc)
468 struct lec_priv *priv = netdev_priv(dev);
473 netif_stop_queue(dev);
474 lec_arp_destroy(priv);
476 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
477 pr_info(
"%s closing with messages pending\n", dev->
name);
478 while ((skb =
skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
488 .close = lec_atm_close,
492 static struct atm_dev lecatm_dev = {
505 const unsigned char *
mac_addr,
const unsigned char *atm_addr,
512 if (!priv || !priv->
lecd)
531 sk = sk_atm(priv->
lecd);
536 pr_debug(
"about to send %d bytes of data\n", data->
len);
546 static int lec_change_mtu(
struct net_device *dev,
int new_mtu)
548 if ((new_mtu < 68) || (new_mtu > 18190))
554 static void lec_set_multicast_list(
struct net_device *dev)
563 .ndo_open = lec_open,
564 .ndo_stop = lec_close,
565 .ndo_start_xmit = lec_start_xmit,
566 .ndo_change_mtu = lec_change_mtu,
567 .ndo_tx_timeout = lec_tx_timeout,
568 .ndo_set_rx_mode = lec_set_multicast_list,
571 static const unsigned char lec_ctrl_magic[] = {
578 #define LEC_DATA_DIRECT_8023 2
579 #define LEC_DATA_DIRECT_8025 3
581 static int lec_is_data_direct(
struct atm_vcc *vcc)
591 struct lec_priv *priv = netdev_priv(dev);
599 lec_vcc_close(priv, vcc);
602 #if DUMP_PACKETS >= 2
603 #define MAX_SKB_DUMP 99
604 #elif DUMP_PACKETS >= 1
605 #define MAX_SKB_DUMP 30
611 skb->
data,
min(MAX_SKB_DUMP, skb->
len),
true);
613 if (
memcmp(skb->
data, lec_ctrl_magic, 4) == 0) {
615 struct sock *sk = sk_atm(vcc);
642 if (lec_is_data_direct(vcc)) {
644 entry = lec_arp_find(priv, src);
645 if (entry && entry->
vcc != vcc) {
646 lec_arp_remove(priv, entry);
652 if (!(dst[0] & 0x01) &&
659 lec_arp_check_empties(priv, vcc, skb);
662 dev->
stats.rx_packets++;
675 pr_info(
"vpriv = NULL!?!?!?\n");
681 if (vpriv->
xoff && atm_may_send(vcc, 0)) {
683 if (netif_running(dev) && netif_queue_stopped(dev))
684 netif_wake_queue(dev);
688 static int lec_vcc_attach(
struct atm_vcc *vcc,
void __user *
arg)
697 pr_info(
"copy from user failed for %d bytes\n", bytes_left);
708 lec_vcc_added(netdev_priv(dev_lec[ioc_data.
dev_num]),
709 &ioc_data, vcc, vcc->
push);
711 vcc->
push = lec_push;
715 static int lec_mcast_attach(
struct atm_vcc *vcc,
int arg)
717 if (arg < 0 || arg >=
MAX_LEC_ITF || !dev_lec[arg])
720 return lec_mcast_make(netdev_priv(dev_lec[arg]), vcc);
724 static int lecd_attach(
struct atm_vcc *vcc,
int arg)
739 dev_lec[
i] = alloc_etherdev(size);
749 priv = netdev_priv(dev_lec[i]);
751 priv = netdev_priv(dev_lec[i]);
758 vcc->
dev = &lecatm_dev;
777 if (dev_lec[i]->flags &
IFF_UP)
778 netif_start_queue(dev_lec[i]);
783 #ifdef CONFIG_PROC_FS
784 static const char *lec_arp_get_status_string(
unsigned char status)
786 static const char *
const lec_arp_status_string[] = {
791 "ESI_FLUSH_PENDING ",
797 return lec_arp_status_string[
status];
810 entry->
flags & 0xffff);
832 static void *lec_tbl_walk(
struct lec_state *
state,
struct hlist_head *tbl,
851 return (*l < 0) ? state :
NULL;
854 static void *lec_arp_walk(
struct lec_state *state, loff_t *l,
865 state->arp_table =
p;
869 static void *lec_misc_walk(
struct lec_state *state, loff_t *l,
880 for (q = state->misc_table; q <
ARRAY_SIZE(lec_misc_tables); q++) {
881 v = lec_tbl_walk(state, lec_misc_tables[q], l);
885 state->misc_table =
q;
889 static void *lec_priv_walk(
struct lec_state *state, loff_t *l,
892 if (!state->locked) {
893 state->locked =
priv;
896 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
897 spin_unlock_irqrestore(&priv->
lec_arp_lock, state->flags);
898 state->locked =
NULL;
900 state->arp_table = state->misc_table = 0;
902 return state->locked;
905 static void *lec_itf_walk(
struct lec_state *state, loff_t *l)
910 dev = state->dev ? state->dev : dev_lec[state->itf];
911 v = (dev && netdev_priv(dev)) ?
912 lec_priv_walk(state, l, netdev_priv(dev)) :
NULL;
922 static void *lec_get_idx(
struct lec_state *state, loff_t l)
927 v = lec_itf_walk(state, &l);
934 static void *lec_seq_start(
struct seq_file *seq, loff_t *
pos)
936 struct lec_state *state = seq->
private;
940 state->locked =
NULL;
941 state->arp_table = 0;
942 state->misc_table = 0;
948 static void lec_seq_stop(
struct seq_file *seq,
void *v)
950 struct lec_state *state = seq->
private;
953 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
959 static void *lec_seq_next(
struct seq_file *seq,
void *v, loff_t *pos)
961 struct lec_state *state = seq->
private;
963 v = lec_get_idx(state, 1);
964 *pos += !!PTR_ERR(v);
968 static int lec_seq_show(
struct seq_file *seq,
void *v)
970 static const char lec_banner[] =
971 "Itf MAC ATM destination"
973 "VPI/VCI Recv VPI/VCI\n";
978 struct lec_state *state = seq->
private;
985 lec_info(seq, entry);
991 .
start = lec_seq_start,
992 .next = lec_seq_next,
993 .stop = lec_seq_stop,
994 .show = lec_seq_show,
1004 .open = lec_seq_open,
1011 static int lane_ioctl(
struct socket *
sock,
unsigned int cmd,
unsigned long arg)
1013 struct atm_vcc *vcc = ATM_SD(sock);
1029 err = lecd_attach(vcc, (
int)arg);
1034 err = lec_mcast_attach(vcc, (
int)arg);
1037 err = lec_vcc_attach(vcc, (
void __user *)arg);
1044 static struct atm_ioctl lane_ioctl_ops = {
1046 .ioctl = lane_ioctl,
1049 static int __init lane_module_init(
void)
1051 #ifdef CONFIG_PROC_FS
1056 pr_err(
"Unable to initialize /proc/net/atm/lec\n");
1062 pr_info(
"lec.c: initialized\n");
1066 static void __exit lane_module_cleanup(
void)
1075 if (dev_lec[i] !=
NULL) {
1094 u8 **tlvs,
u32 *sizeoftlvs)
1096 unsigned long flags;
1097 struct lec_priv *priv = netdev_priv(dev);
1104 table = lec_arp_find(priv, dst_mac);
1118 if (sizeoftlvs ==
NULL)
1125 skb->
len = *sizeoftlvs;
1126 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
1139 static int lane2_associate_req(
struct net_device *dev,
const u8 *lan_dst,
1140 const u8 *tlvs,
u32 sizeoftlvs)
1144 struct lec_priv *priv = netdev_priv(dev);
1146 if (!ether_addr_equal(lan_dst, dev->
dev_addr))
1160 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
1163 pr_info(
"lec.c: lane2_associate_req() failed\n");
1175 static void lane2_associate_ind(
struct net_device *dev,
const u8 *mac_addr,
1176 const u8 *tlvs,
u32 sizeoftlvs)
1181 struct lec_priv *priv = netdev_priv(dev);
1202 pr_info(
"dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1203 while (i < sizeoftlvs)
1211 priv->
lane2_ops->associate_indicator(dev, mac_addr,
1223 #include <linux/types.h>
1231 #define pr_debug(format, args...)
1236 #define DEBUG_ARP_TABLE 0
1238 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1241 static void lec_arp_expire_arp(
unsigned long data);
1247 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
1252 static void lec_arp_init(
struct lec_priv *priv)
1275 netif_wake_queue(dev);
1299 hlist_add_head(&entry->
next, tmp);
1312 int i, remove_vcc = 1;
1317 hlist_del(&to_remove->
next);
1332 entry->
atm_addr, ATM_ESA_LEN) == 0) {
1339 lec_arp_clear_vccs(to_remove);
1348 static const char *get_status_string(
unsigned char st)
1352 return "ESI_UNKNOWN";
1354 return "ESI_ARP_PENDING";
1356 return "ESI_VC_PENDING";
1358 return "ESI_FLUSH_PENDING";
1360 return "ESI_FORWARD_DIRECT";
1377 offset +=
sprintf(buf,
"%d: %p\n", i, rulla);
1378 offset +=
sprintf(buf + offset,
"Mac: %pM",
1380 offset +=
sprintf(buf + offset,
" Atm:");
1382 offset +=
sprintf(buf + offset,
1386 offset +=
sprintf(buf + offset,
1387 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1388 rulla->
vcc ? rulla->
vcc->vpi : 0,
1389 rulla->
vcc ? rulla->
vcc->vci : 0,
1397 "Flags:%x, Packets_flooded:%x, Status: %s ",
1399 get_status_string(rulla->
status));
1409 offset +=
sprintf(buf + offset,
" Atm:");
1411 offset +=
sprintf(buf + offset,
"%2.2x ",
1414 offset +=
sprintf(buf + offset,
1415 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1416 rulla->
vcc ? rulla->
vcc->vpi : 0,
1417 rulla->
vcc ? rulla->
vcc->vci : 0,
1422 offset +=
sprintf(buf + offset,
1423 "Flags:%x, Packets_flooded:%x, Status: %s ",
1425 get_status_string(rulla->
status));
1434 offset +=
sprintf(buf + offset,
" Atm:");
1436 offset +=
sprintf(buf + offset,
"%2.2x ",
1439 offset +=
sprintf(buf + offset,
1440 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1441 rulla->
vcc ? rulla->
vcc->vpi : 0,
1442 rulla->
vcc ? rulla->
vcc->vci : 0,
1447 offset +=
sprintf(buf + offset,
1448 "Flags:%x, Packets_flooded:%x, Status: %s ",
1450 get_status_string(rulla->
status));
1455 pr_info(
"Multicast Forward VCCs\n");
1459 offset +=
sprintf(buf + offset,
" Atm:");
1461 offset +=
sprintf(buf + offset,
"%2.2x ",
1464 offset +=
sprintf(buf + offset,
1465 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1466 rulla->
vcc ? rulla->
vcc->vpi : 0,
1467 rulla->
vcc ? rulla->
vcc->vci : 0,
1472 offset +=
sprintf(buf + offset,
1473 "Flags:%x, Packets_flooded:%x, Status: %s ",
1475 get_status_string(rulla->
status));
1481 #define dump_arp_table(priv) do { } while (0)
1487 static void lec_arp_destroy(
struct lec_priv *priv)
1489 unsigned long flags;
1504 lec_arp_remove(priv, entry);
1513 lec_arp_clear_vccs(entry);
1514 hlist_del(&entry->
next);
1522 lec_arp_clear_vccs(entry);
1523 hlist_del(&entry->
next);
1530 lec_arp_clear_vccs(entry);
1531 hlist_del(&entry->
next);
1543 const unsigned char *mac_addr)
1553 if (ether_addr_equal(mac_addr, entry->
mac_addr))
1560 const unsigned char *mac_addr)
1566 pr_info(
"LEC: Arp entry kmalloc failed\n");
1570 INIT_HLIST_NODE(&to_return->
next);
1572 (
unsigned long)to_return);
1575 skb_queue_head_init(&to_return->
tx_wait);
1581 static void lec_arp_expire_arp(
unsigned long data)
1603 static void lec_arp_expire_vcc(
unsigned long data)
1605 unsigned long flags;
1617 hlist_del(&to_remove->
next);
1620 lec_arp_clear_vccs(to_remove);
1621 lec_arp_put(to_remove);
1624 static bool __lec_arp_check_expire(
struct lec_arp_table *entry,
1628 unsigned long time_to_check;
1635 pr_debug(
"About to expire: %lx - %lx > %lx\n",
1642 lec_arp_remove(priv, entry);
1661 lec_arp_hold(entry);
1686 unsigned long flags;
1701 if (__lec_arp_check_expire(entry, now, priv)) {
1727 const unsigned char *mac_to_find,
1731 unsigned long flags;
1735 if (mac_to_find[0] & 0x01) {
1740 if (ether_addr_equal(mac_to_find, bus_mac))
1749 entry = lec_arp_find(priv, mac_to_find);
1755 lec_arp_hold(entry);
1785 lec_arp_hold(entry);
1792 entry = make_entry(priv, mac_to_find);
1798 lec_arp_add(priv, entry);
1811 entry->
timer.function = lec_arp_expire_arp;
1822 lec_addr_delete(
struct lec_priv *priv,
const unsigned char *atm_addr,
1823 unsigned long permanent)
1825 unsigned long flags;
1838 lec_arp_remove(priv, entry);
1853 lec_arp_update(
struct lec_priv *priv,
const unsigned char *mac_addr,
1854 const unsigned char *atm_addr,
unsigned long remoteflag,
1855 unsigned int targetless_le_arp)
1857 unsigned long flags;
1863 (targetless_le_arp) ?
"targetless " :
"", mac_addr);
1866 entry = lec_arp_find(priv, mac_addr);
1867 if (entry ==
NULL && targetless_le_arp)
1876 hlist_del(&entry->
next);
1878 tmp = lec_arp_find(priv, mac_addr);
1893 lec_arp_add(priv, entry);
1906 entry = lec_arp_find(priv, mac_addr);
1908 entry = make_entry(priv, mac_addr);
1912 lec_arp_add(priv, entry);
1958 unsigned long flags;
1961 int i, found_entry = 0;
1966 pr_debug(
"LEC_ARP: Attaching mcast forward\n");
1968 entry = lec_arp_find(priv, bus_mac);
1970 pr_info(
"LEC_ARP: Multicast entry not found!\n");
1977 entry = make_entry(priv, bus_mac);
1986 }
else if (ioc_data->
receive == 1) {
1991 pr_debug(
"LEC_ARP:Attaching data direct, not default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2002 entry = make_entry(priv, bus_mac);
2011 entry->
timer.function = lec_arp_expire_vcc;
2017 pr_debug(
"LEC_ARP:Attaching data direct, default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2033 ATM_ESA_LEN) == 0) {
2034 pr_debug(
"LEC_ARP: Attaching data direct\n");
2035 pr_debug(
"Currently -> Vcc: %d, Rvcc:%d\n",
2036 entry->
vcc ? entry->
vcc->vci : 0,
2053 send_to_lecd(priv, l_flush_xmt,
2085 entry = make_entry(priv, bus_mac);
2095 entry->
timer.function = lec_arp_expire_vcc;
2103 static void lec_flush_complete(
struct lec_priv *priv,
unsigned long tran_id)
2105 unsigned long flags;
2121 lec_arp_hold(entry);
2139 lec_set_flush_tran_id(
struct lec_priv *priv,
2140 const unsigned char *atm_addr,
unsigned long tran_id)
2142 unsigned long flags;
2153 pr_debug(
"Set flush transaction id to %lx for %p\n",
2162 unsigned long flags;
2163 unsigned char mac_addr[] = {
2164 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2178 to_add = make_entry(priv, mac_addr);
2190 vcc->
push = lec_push;
2192 lec_arp_add(priv, to_add);
2200 unsigned long flags;
2205 pr_debug(
"LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->
vpi, vcc->
vci);
2213 if (vcc == entry->
vcc) {
2214 lec_arp_remove(priv, entry);
2224 if (entry->
vcc == vcc) {
2225 lec_arp_clear_vccs(entry);
2227 hlist_del(&entry->
next);
2235 lec_arp_clear_vccs(entry);
2237 hlist_del(&entry->
next);
2244 lec_arp_clear_vccs(entry);
2246 hlist_del(&entry->
next);
2256 lec_arp_check_empties(
struct lec_priv *priv,
2259 unsigned long flags;
2263 unsigned char *src = hdr->
h_source;
2268 if (vcc == entry->
vcc) {
2274 tmp = lec_arp_find(priv, src);
2276 lec_arp_remove(priv, tmp);
2279 hlist_del(&entry->
next);
2280 lec_arp_add(priv, entry);
2284 pr_debug(
"LEC_ARP: Arp_check_empties: entry not found!\n");