11da177e4SLinus Torvalds /* net/atm/clip.c - RFC1577 Classical IP over ATM */ 21da177e4SLinus Torvalds 31da177e4SLinus Torvalds /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 41da177e4SLinus Torvalds 599824461SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ 699824461SJoe Perches 71da177e4SLinus Torvalds #include <linux/string.h> 81da177e4SLinus Torvalds #include <linux/errno.h> 91da177e4SLinus Torvalds #include <linux/kernel.h> /* for UINT_MAX */ 101da177e4SLinus Torvalds #include <linux/module.h> 111da177e4SLinus Torvalds #include <linux/init.h> 121da177e4SLinus Torvalds #include <linux/netdevice.h> 131da177e4SLinus Torvalds #include <linux/skbuff.h> 141da177e4SLinus Torvalds #include <linux/wait.h> 151da177e4SLinus Torvalds #include <linux/timer.h> 161da177e4SLinus Torvalds #include <linux/if_arp.h> /* for some manifest constants */ 171da177e4SLinus Torvalds #include <linux/notifier.h> 181da177e4SLinus Torvalds #include <linux/atm.h> 191da177e4SLinus Torvalds #include <linux/atmdev.h> 201da177e4SLinus Torvalds #include <linux/atmclip.h> 211da177e4SLinus Torvalds #include <linux/atmarp.h> 224fc268d2SRandy Dunlap #include <linux/capability.h> 231da177e4SLinus Torvalds #include <linux/ip.h> /* for net/route.h */ 241da177e4SLinus Torvalds #include <linux/in.h> /* for struct sockaddr_in */ 251da177e4SLinus Torvalds #include <linux/if.h> /* for IFF_UP */ 261da177e4SLinus Torvalds #include <linux/inetdevice.h> 271da177e4SLinus Torvalds #include <linux/bitops.h> 284bdbf6c0SRandy Dunlap #include <linux/poison.h> 291da177e4SLinus Torvalds #include <linux/proc_fs.h> 301da177e4SLinus Torvalds #include <linux/seq_file.h> 311da177e4SLinus Torvalds #include <linux/rcupdate.h> 321da177e4SLinus Torvalds #include <linux/jhash.h> 335a0e3ad6STejun Heo #include <linux/slab.h> 341da177e4SLinus Torvalds #include <net/route.h> /* for struct rtable and routing */ 351da177e4SLinus Torvalds #include <net/icmp.h> /* icmp_send */ 3632092ecfSDavid Miller #include <net/arp.h> 37e956ea1bSJoe Perches #include <linux/param.h> /* for HZ */ 38e956ea1bSJoe Perches #include <linux/uaccess.h> 391da177e4SLinus Torvalds #include <asm/byteorder.h> /* for htons etc. */ 4060063497SArun Sharma #include <linux/atomic.h> 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #include "common.h" 431da177e4SLinus Torvalds #include "resources.h" 441da177e4SLinus Torvalds #include <net/atmclip.h> 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds static struct net_device *clip_devs; 471da177e4SLinus Torvalds static struct atm_vcc *atmarpd; 481da177e4SLinus Torvalds static struct timer_list idle_timer; 49597cdbc2SEric Dumazet static const struct neigh_ops clip_neigh_ops; 501da177e4SLinus Torvalds 5130d492daSAl Viro static int to_atmarpd(enum atmarp_ctrl_type type, int itf, __be32 ip) 521da177e4SLinus Torvalds { 531da177e4SLinus Torvalds struct sock *sk; 541da177e4SLinus Torvalds struct atmarp_ctrl *ctrl; 551da177e4SLinus Torvalds struct sk_buff *skb; 561da177e4SLinus Torvalds 5799824461SJoe Perches pr_debug("(%d)\n", type); 58e49e76dbSStephen Hemminger if (!atmarpd) 59e49e76dbSStephen Hemminger return -EUNATCH; 601da177e4SLinus Torvalds skb = alloc_skb(sizeof(struct atmarp_ctrl), GFP_ATOMIC); 61e49e76dbSStephen Hemminger if (!skb) 62e49e76dbSStephen Hemminger return -ENOMEM; 634df864c1SJohannes Berg ctrl = skb_put(skb, sizeof(struct atmarp_ctrl)); 641da177e4SLinus Torvalds ctrl->type = type; 651da177e4SLinus Torvalds ctrl->itf_num = itf; 661da177e4SLinus Torvalds ctrl->ip = ip; 671da177e4SLinus Torvalds atm_force_charge(atmarpd, skb->truesize); 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds sk = sk_atm(atmarpd); 701da177e4SLinus Torvalds skb_queue_tail(&sk->sk_receive_queue, skb); 71676d2369SDavid S. Miller sk->sk_data_ready(sk); 721da177e4SLinus Torvalds return 0; 731da177e4SLinus Torvalds } 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds static void link_vcc(struct clip_vcc *clip_vcc, struct atmarp_entry *entry) 761da177e4SLinus Torvalds { 7799824461SJoe Perches pr_debug("%p to entry %p (neigh %p)\n", clip_vcc, entry, entry->neigh); 781da177e4SLinus Torvalds clip_vcc->entry = entry; 791da177e4SLinus Torvalds clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */ 801da177e4SLinus Torvalds clip_vcc->next = entry->vccs; 811da177e4SLinus Torvalds entry->vccs = clip_vcc; 821da177e4SLinus Torvalds entry->neigh->used = jiffies; 831da177e4SLinus Torvalds } 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds static void unlink_clip_vcc(struct clip_vcc *clip_vcc) 861da177e4SLinus Torvalds { 871da177e4SLinus Torvalds struct atmarp_entry *entry = clip_vcc->entry; 881da177e4SLinus Torvalds struct clip_vcc **walk; 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds if (!entry) { 9199824461SJoe Perches pr_crit("!clip_vcc->entry (clip_vcc %p)\n", clip_vcc); 921da177e4SLinus Torvalds return; 931da177e4SLinus Torvalds } 94932ff279SHerbert Xu netif_tx_lock_bh(entry->neigh->dev); /* block clip_start_xmit() */ 951da177e4SLinus Torvalds entry->neigh->used = jiffies; 961da177e4SLinus Torvalds for (walk = &entry->vccs; *walk; walk = &(*walk)->next) 971da177e4SLinus Torvalds if (*walk == clip_vcc) { 981da177e4SLinus Torvalds int error; 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds *walk = clip_vcc->next; /* atomic */ 1011da177e4SLinus Torvalds clip_vcc->entry = NULL; 1021da177e4SLinus Torvalds if (clip_vcc->xoff) 1031da177e4SLinus Torvalds netif_wake_queue(entry->neigh->dev); 1041da177e4SLinus Torvalds if (entry->vccs) 1051da177e4SLinus Torvalds goto out; 1061da177e4SLinus Torvalds entry->expires = jiffies - 1; 1071da177e4SLinus Torvalds /* force resolution or expiration */ 1081da177e4SLinus Torvalds error = neigh_update(entry->neigh, NULL, NUD_NONE, 1097b8f7a40SRoopa Prabhu NEIGH_UPDATE_F_ADMIN, 0); 1101da177e4SLinus Torvalds if (error) 11199824461SJoe Perches pr_crit("neigh_update failed with %d\n", error); 1121da177e4SLinus Torvalds goto out; 1131da177e4SLinus Torvalds } 11499824461SJoe Perches pr_crit("ATMARP: failed (entry %p, vcc 0x%p)\n", entry, clip_vcc); 1151da177e4SLinus Torvalds out: 116932ff279SHerbert Xu netif_tx_unlock_bh(entry->neigh->dev); 1171da177e4SLinus Torvalds } 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds /* The neighbour entry n->lock is held. */ 1201da177e4SLinus Torvalds static int neigh_check_cb(struct neighbour *n) 1211da177e4SLinus Torvalds { 122869759b9SDavid Miller struct atmarp_entry *entry = neighbour_priv(n); 1231da177e4SLinus Torvalds struct clip_vcc *cv; 1241da177e4SLinus Torvalds 125597cdbc2SEric Dumazet if (n->ops != &clip_neigh_ops) 126597cdbc2SEric Dumazet return 0; 1271da177e4SLinus Torvalds for (cv = entry->vccs; cv; cv = cv->next) { 1281da177e4SLinus Torvalds unsigned long exp = cv->last_use + cv->idle_timeout; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds if (cv->idle_timeout && time_after(jiffies, exp)) { 13152240062SStephen Hemminger pr_debug("releasing vcc %p->%p of entry %p\n", 1321da177e4SLinus Torvalds cv, cv->vcc, entry); 1331da177e4SLinus Torvalds vcc_release_async(cv->vcc, -ETIMEDOUT); 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds if (entry->vccs || time_before(jiffies, entry->expires)) 1381da177e4SLinus Torvalds return 0; 1391da177e4SLinus Torvalds 1409f237430SReshetova, Elena if (refcount_read(&n->refcnt) > 1) { 1411da177e4SLinus Torvalds struct sk_buff *skb; 1421da177e4SLinus Torvalds 14352240062SStephen Hemminger pr_debug("destruction postponed with ref %d\n", 1449f237430SReshetova, Elena refcount_read(&n->refcnt)); 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds while ((skb = skb_dequeue(&n->arp_queue)) != NULL) 1471da177e4SLinus Torvalds dev_kfree_skb(skb); 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds return 0; 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds 15252240062SStephen Hemminger pr_debug("expired neigh %p\n", n); 1531da177e4SLinus Torvalds return 1; 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds 156ba421793SKees Cook static void idle_timer_check(struct timer_list *unused) 1571da177e4SLinus Torvalds { 158597cdbc2SEric Dumazet write_lock(&arp_tbl.lock); 159597cdbc2SEric Dumazet __neigh_for_each_release(&arp_tbl, neigh_check_cb); 1601da177e4SLinus Torvalds mod_timer(&idle_timer, jiffies + CLIP_CHECK_INTERVAL * HZ); 161597cdbc2SEric Dumazet write_unlock(&arp_tbl.lock); 1621da177e4SLinus Torvalds } 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds static int clip_arp_rcv(struct sk_buff *skb) 1651da177e4SLinus Torvalds { 1661da177e4SLinus Torvalds struct atm_vcc *vcc; 1671da177e4SLinus Torvalds 16899824461SJoe Perches pr_debug("\n"); 1691da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc; 1701da177e4SLinus Torvalds if (!vcc || !atm_charge(vcc, skb->truesize)) { 1711da177e4SLinus Torvalds dev_kfree_skb_any(skb); 1721da177e4SLinus Torvalds return 0; 1731da177e4SLinus Torvalds } 17452240062SStephen Hemminger pr_debug("pushing to %p\n", vcc); 17552240062SStephen Hemminger pr_debug("using %p\n", CLIP_VCC(vcc)->old_push); 1761da177e4SLinus Torvalds CLIP_VCC(vcc)->old_push(vcc, skb); 1771da177e4SLinus Torvalds return 0; 1781da177e4SLinus Torvalds } 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds static const unsigned char llc_oui[] = { 1811da177e4SLinus Torvalds 0xaa, /* DSAP: non-ISO */ 1821da177e4SLinus Torvalds 0xaa, /* SSAP: non-ISO */ 1831da177e4SLinus Torvalds 0x03, /* Ctrl: Unnumbered Information Command PDU */ 1841da177e4SLinus Torvalds 0x00, /* OUI: EtherType */ 1851da177e4SLinus Torvalds 0x00, 186e49e76dbSStephen Hemminger 0x00 187e49e76dbSStephen Hemminger }; 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds static void clip_push(struct atm_vcc *vcc, struct sk_buff *skb) 1901da177e4SLinus Torvalds { 1911da177e4SLinus Torvalds struct clip_vcc *clip_vcc = CLIP_VCC(vcc); 1921da177e4SLinus Torvalds 19399824461SJoe Perches pr_debug("\n"); 1943b829366SJorge Boncompte [DTI2] 1953b829366SJorge Boncompte [DTI2] if (!clip_devs) { 1963b829366SJorge Boncompte [DTI2] atm_return(vcc, skb->truesize); 1973b829366SJorge Boncompte [DTI2] kfree_skb(skb); 1983b829366SJorge Boncompte [DTI2] return; 1993b829366SJorge Boncompte [DTI2] } 2003b829366SJorge Boncompte [DTI2] 2011da177e4SLinus Torvalds if (!skb) { 20252240062SStephen Hemminger pr_debug("removing VCC %p\n", clip_vcc); 203e49e76dbSStephen Hemminger if (clip_vcc->entry) 204e49e76dbSStephen Hemminger unlink_clip_vcc(clip_vcc); 2051da177e4SLinus Torvalds clip_vcc->old_push(vcc, NULL); /* pass on the bad news */ 2061da177e4SLinus Torvalds kfree(clip_vcc); 2071da177e4SLinus Torvalds return; 2081da177e4SLinus Torvalds } 2091da177e4SLinus Torvalds atm_return(vcc, skb->truesize); 2101da177e4SLinus Torvalds skb->dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : clip_devs; 2111da177e4SLinus Torvalds /* clip_vcc->entry == NULL if we don't have an IP address yet */ 2121da177e4SLinus Torvalds if (!skb->dev) { 2131da177e4SLinus Torvalds dev_kfree_skb_any(skb); 2141da177e4SLinus Torvalds return; 2151da177e4SLinus Torvalds } 2161da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc; 217459a98edSArnaldo Carvalho de Melo skb_reset_mac_header(skb); 218e956ea1bSJoe Perches if (!clip_vcc->encap || 219e956ea1bSJoe Perches skb->len < RFC1483LLC_LEN || 220e956ea1bSJoe Perches memcmp(skb->data, llc_oui, sizeof(llc_oui))) 221e49e76dbSStephen Hemminger skb->protocol = htons(ETH_P_IP); 2221da177e4SLinus Torvalds else { 22330d492daSAl Viro skb->protocol = ((__be16 *)skb->data)[3]; 2241da177e4SLinus Torvalds skb_pull(skb, RFC1483LLC_LEN); 2251da177e4SLinus Torvalds if (skb->protocol == htons(ETH_P_ARP)) { 2261a6afe8aSStephen Hemminger skb->dev->stats.rx_packets++; 2271a6afe8aSStephen Hemminger skb->dev->stats.rx_bytes += skb->len; 2281da177e4SLinus Torvalds clip_arp_rcv(skb); 2291da177e4SLinus Torvalds return; 2301da177e4SLinus Torvalds } 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds clip_vcc->last_use = jiffies; 2331a6afe8aSStephen Hemminger skb->dev->stats.rx_packets++; 2341a6afe8aSStephen Hemminger skb->dev->stats.rx_bytes += skb->len; 2351da177e4SLinus Torvalds memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data)); 2361da177e4SLinus Torvalds netif_rx(skb); 2371da177e4SLinus Torvalds } 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds /* 2401da177e4SLinus Torvalds * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that 2411da177e4SLinus Torvalds * clip_pop is atomic with respect to the critical section in clip_start_xmit. 2421da177e4SLinus Torvalds */ 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds static void clip_pop(struct atm_vcc *vcc, struct sk_buff *skb) 2451da177e4SLinus Torvalds { 2461da177e4SLinus Torvalds struct clip_vcc *clip_vcc = CLIP_VCC(vcc); 2471da177e4SLinus Torvalds struct net_device *dev = skb->dev; 2481da177e4SLinus Torvalds int old; 2491da177e4SLinus Torvalds unsigned long flags; 2501da177e4SLinus Torvalds 25199824461SJoe Perches pr_debug("(vcc %p)\n", vcc); 2521da177e4SLinus Torvalds clip_vcc->old_pop(vcc, skb); 2531da177e4SLinus Torvalds /* skb->dev == NULL in outbound ARP packets */ 254e49e76dbSStephen Hemminger if (!dev) 255e49e76dbSStephen Hemminger return; 2561da177e4SLinus Torvalds spin_lock_irqsave(&PRIV(dev)->xoff_lock, flags); 2571da177e4SLinus Torvalds if (atm_may_send(vcc, 0)) { 2581da177e4SLinus Torvalds old = xchg(&clip_vcc->xoff, 0); 259e49e76dbSStephen Hemminger if (old) 260e49e76dbSStephen Hemminger netif_wake_queue(dev); 2611da177e4SLinus Torvalds } 2621da177e4SLinus Torvalds spin_unlock_irqrestore(&PRIV(dev)->xoff_lock, flags); 2631da177e4SLinus Torvalds } 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds static void clip_neigh_solicit(struct neighbour *neigh, struct sk_buff *skb) 2661da177e4SLinus Torvalds { 267869759b9SDavid Miller __be32 *ip = (__be32 *) neigh->primary_key; 268869759b9SDavid Miller 26999824461SJoe Perches pr_debug("(neigh %p, skb %p)\n", neigh, skb); 270869759b9SDavid Miller to_atmarpd(act_need, PRIV(neigh->dev)->number, *ip); 2711da177e4SLinus Torvalds } 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds static void clip_neigh_error(struct neighbour *neigh, struct sk_buff *skb) 2741da177e4SLinus Torvalds { 2751da177e4SLinus Torvalds #ifndef CONFIG_ATM_CLIP_NO_ICMP 2761da177e4SLinus Torvalds icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0); 2771da177e4SLinus Torvalds #endif 2781da177e4SLinus Torvalds kfree_skb(skb); 2791da177e4SLinus Torvalds } 2801da177e4SLinus Torvalds 28189d69d2bSStephen Hemminger static const struct neigh_ops clip_neigh_ops = { 2821da177e4SLinus Torvalds .family = AF_INET, 2831da177e4SLinus Torvalds .solicit = clip_neigh_solicit, 2841da177e4SLinus Torvalds .error_report = clip_neigh_error, 2858f40b161SDavid S. Miller .output = neigh_direct_output, 2868f40b161SDavid S. Miller .connected_output = neigh_direct_output, 2871da177e4SLinus Torvalds }; 2881da177e4SLinus Torvalds 289503eebc2SJiri Pirko static int clip_constructor(struct net_device *dev, struct neighbour *neigh) 2901da177e4SLinus Torvalds { 291869759b9SDavid Miller struct atmarp_entry *entry = neighbour_priv(neigh); 2921da177e4SLinus Torvalds 29332092ecfSDavid Miller if (neigh->tbl->family != AF_INET) 29432092ecfSDavid Miller return -EINVAL; 29532092ecfSDavid Miller 296e49e76dbSStephen Hemminger if (neigh->type != RTN_UNICAST) 297e49e76dbSStephen Hemminger return -EINVAL; 2981da177e4SLinus Torvalds 29932092ecfSDavid Miller neigh->nud_state = NUD_NONE; 3001da177e4SLinus Torvalds neigh->ops = &clip_neigh_ops; 30132092ecfSDavid Miller neigh->output = neigh->ops->output; 3021da177e4SLinus Torvalds entry->neigh = neigh; 3031da177e4SLinus Torvalds entry->vccs = NULL; 3041da177e4SLinus Torvalds entry->expires = jiffies - 1; 30532092ecfSDavid Miller 3061da177e4SLinus Torvalds return 0; 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */ 3101da177e4SLinus Torvalds 3111da177e4SLinus Torvalds /* 3121da177e4SLinus Torvalds * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means 3131da177e4SLinus Torvalds * to allocate the neighbour entry but not to ask atmarpd for resolution. Also, 3141da177e4SLinus Torvalds * don't increment the usage count. This is used to create entries in 3151da177e4SLinus Torvalds * clip_setentry. 3161da177e4SLinus Torvalds */ 3171da177e4SLinus Torvalds 3181da177e4SLinus Torvalds static int clip_encap(struct atm_vcc *vcc, int mode) 3191da177e4SLinus Torvalds { 32034f5b006SSasha Levin if (!CLIP_VCC(vcc)) 32134f5b006SSasha Levin return -EBADFD; 32234f5b006SSasha Levin 3231da177e4SLinus Torvalds CLIP_VCC(vcc)->encap = mode; 3241da177e4SLinus Torvalds return 0; 3251da177e4SLinus Torvalds } 3261da177e4SLinus Torvalds 3273c805a22SStephen Hemminger static netdev_tx_t clip_start_xmit(struct sk_buff *skb, 3283c805a22SStephen Hemminger struct net_device *dev) 3291da177e4SLinus Torvalds { 3301da177e4SLinus Torvalds struct clip_priv *clip_priv = PRIV(dev); 33169cce1d1SDavid S. Miller struct dst_entry *dst = skb_dst(skb); 3321da177e4SLinus Torvalds struct atmarp_entry *entry; 33369cce1d1SDavid S. Miller struct neighbour *n; 3341da177e4SLinus Torvalds struct atm_vcc *vcc; 3357161c76fSDavid S. Miller struct rtable *rt; 3367161c76fSDavid S. Miller __be32 *daddr; 3371da177e4SLinus Torvalds int old; 3381da177e4SLinus Torvalds unsigned long flags; 3391da177e4SLinus Torvalds 34099824461SJoe Perches pr_debug("(skb %p)\n", skb); 34169cce1d1SDavid S. Miller if (!dst) { 34299824461SJoe Perches pr_err("skb_dst(skb) == NULL\n"); 3431da177e4SLinus Torvalds dev_kfree_skb(skb); 3441a6afe8aSStephen Hemminger dev->stats.tx_dropped++; 3456ed10654SPatrick McHardy return NETDEV_TX_OK; 3461da177e4SLinus Torvalds } 3477161c76fSDavid S. Miller rt = (struct rtable *) dst; 3487161c76fSDavid S. Miller if (rt->rt_gateway) 3497161c76fSDavid S. Miller daddr = &rt->rt_gateway; 3507161c76fSDavid S. Miller else 3517161c76fSDavid S. Miller daddr = &ip_hdr(skb)->daddr; 3527161c76fSDavid S. Miller n = dst_neigh_lookup(dst, daddr); 35369cce1d1SDavid S. Miller if (!n) { 35499824461SJoe Perches pr_err("NO NEIGHBOUR !\n"); 3551da177e4SLinus Torvalds dev_kfree_skb(skb); 3561a6afe8aSStephen Hemminger dev->stats.tx_dropped++; 3576ed10654SPatrick McHardy return NETDEV_TX_OK; 3581da177e4SLinus Torvalds } 359869759b9SDavid Miller entry = neighbour_priv(n); 3601da177e4SLinus Torvalds if (!entry->vccs) { 3611da177e4SLinus Torvalds if (time_after(jiffies, entry->expires)) { 3621da177e4SLinus Torvalds /* should be resolved */ 3631da177e4SLinus Torvalds entry->expires = jiffies + ATMARP_RETRY_DELAY * HZ; 364869759b9SDavid Miller to_atmarpd(act_need, PRIV(dev)->number, *((__be32 *)n->primary_key)); 3651da177e4SLinus Torvalds } 3661da177e4SLinus Torvalds if (entry->neigh->arp_queue.qlen < ATMARP_MAX_UNRES_PACKETS) 3671da177e4SLinus Torvalds skb_queue_tail(&entry->neigh->arp_queue, skb); 3681da177e4SLinus Torvalds else { 3691da177e4SLinus Torvalds dev_kfree_skb(skb); 3701a6afe8aSStephen Hemminger dev->stats.tx_dropped++; 3711da177e4SLinus Torvalds } 3727161c76fSDavid S. Miller goto out_release_neigh; 3731da177e4SLinus Torvalds } 37452240062SStephen Hemminger pr_debug("neigh %p, vccs %p\n", entry, entry->vccs); 3751da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc; 37669cce1d1SDavid S. Miller pr_debug("using neighbour %p, vcc %p\n", n, vcc); 3771da177e4SLinus Torvalds if (entry->vccs->encap) { 3781da177e4SLinus Torvalds void *here; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds here = skb_push(skb, RFC1483LLC_LEN); 3811da177e4SLinus Torvalds memcpy(here, llc_oui, sizeof(llc_oui)); 38230d492daSAl Viro ((__be16 *) here)[3] = skb->protocol; 3831da177e4SLinus Torvalds } 384*9bbe60a6SDavid Woodhouse atm_account_tx(vcc, skb); 3851da177e4SLinus Torvalds entry->vccs->last_use = jiffies; 38652240062SStephen Hemminger pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->dev); 3871da177e4SLinus Torvalds old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */ 3881da177e4SLinus Torvalds if (old) { 389ef423a41SJoe Perches pr_warn("XOFF->XOFF transition\n"); 3907161c76fSDavid S. Miller goto out_release_neigh; 3911da177e4SLinus Torvalds } 3921a6afe8aSStephen Hemminger dev->stats.tx_packets++; 3931a6afe8aSStephen Hemminger dev->stats.tx_bytes += skb->len; 3945ff765f3SStephen Hemminger vcc->send(vcc, skb); 3951da177e4SLinus Torvalds if (atm_may_send(vcc, 0)) { 3961da177e4SLinus Torvalds entry->vccs->xoff = 0; 3977161c76fSDavid S. Miller goto out_release_neigh; 3981da177e4SLinus Torvalds } 3991da177e4SLinus Torvalds spin_lock_irqsave(&clip_priv->xoff_lock, flags); 4001da177e4SLinus Torvalds netif_stop_queue(dev); /* XOFF -> throttle immediately */ 4011da177e4SLinus Torvalds barrier(); 4021da177e4SLinus Torvalds if (!entry->vccs->xoff) 4031da177e4SLinus Torvalds netif_start_queue(dev); 4041da177e4SLinus Torvalds /* Oh, we just raced with clip_pop. netif_start_queue should be 4051da177e4SLinus Torvalds good enough, because nothing should really be asleep because 4061da177e4SLinus Torvalds of the brief netif_stop_queue. If this isn't true or if it 4071da177e4SLinus Torvalds changes, use netif_wake_queue instead. */ 4081da177e4SLinus Torvalds spin_unlock_irqrestore(&clip_priv->xoff_lock, flags); 4097161c76fSDavid S. Miller out_release_neigh: 4107161c76fSDavid S. Miller neigh_release(n); 4116ed10654SPatrick McHardy return NETDEV_TX_OK; 4121da177e4SLinus Torvalds } 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvalds static int clip_mkip(struct atm_vcc *vcc, int timeout) 4151da177e4SLinus Torvalds { 4161da177e4SLinus Torvalds struct clip_vcc *clip_vcc; 4171da177e4SLinus Torvalds 418e49e76dbSStephen Hemminger if (!vcc->push) 419e49e76dbSStephen Hemminger return -EBADFD; 4201da177e4SLinus Torvalds clip_vcc = kmalloc(sizeof(struct clip_vcc), GFP_KERNEL); 421e49e76dbSStephen Hemminger if (!clip_vcc) 422e49e76dbSStephen Hemminger return -ENOMEM; 42399824461SJoe Perches pr_debug("%p vcc %p\n", clip_vcc, vcc); 4241da177e4SLinus Torvalds clip_vcc->vcc = vcc; 4251da177e4SLinus Torvalds vcc->user_back = clip_vcc; 4261da177e4SLinus Torvalds set_bit(ATM_VF_IS_CLIP, &vcc->flags); 4271da177e4SLinus Torvalds clip_vcc->entry = NULL; 4281da177e4SLinus Torvalds clip_vcc->xoff = 0; 4291da177e4SLinus Torvalds clip_vcc->encap = 1; 4301da177e4SLinus Torvalds clip_vcc->last_use = jiffies; 4311da177e4SLinus Torvalds clip_vcc->idle_timeout = timeout * HZ; 4321da177e4SLinus Torvalds clip_vcc->old_push = vcc->push; 4331da177e4SLinus Torvalds clip_vcc->old_pop = vcc->pop; 4341da177e4SLinus Torvalds vcc->push = clip_push; 4351da177e4SLinus Torvalds vcc->pop = clip_pop; 436c40a27f4SDavid S. Miller 4371da177e4SLinus Torvalds /* re-process everything received between connection setup and MKIP */ 4384e55f578SJorge Boncompte [DTI2] vcc_process_recv_queue(vcc); 4393b829366SJorge Boncompte [DTI2] 4401da177e4SLinus Torvalds return 0; 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds 44330d492daSAl Viro static int clip_setentry(struct atm_vcc *vcc, __be32 ip) 4441da177e4SLinus Torvalds { 4451da177e4SLinus Torvalds struct neighbour *neigh; 4461da177e4SLinus Torvalds struct atmarp_entry *entry; 4471da177e4SLinus Torvalds int error; 4481da177e4SLinus Torvalds struct clip_vcc *clip_vcc; 4491da177e4SLinus Torvalds struct rtable *rt; 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds if (vcc->push != clip_push) { 452ef423a41SJoe Perches pr_warn("non-CLIP VCC\n"); 4531da177e4SLinus Torvalds return -EBADF; 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds clip_vcc = CLIP_VCC(vcc); 4561da177e4SLinus Torvalds if (!ip) { 4571da177e4SLinus Torvalds if (!clip_vcc->entry) { 45899824461SJoe Perches pr_err("hiding hidden ATMARP entry\n"); 4591da177e4SLinus Torvalds return 0; 4601da177e4SLinus Torvalds } 46199824461SJoe Perches pr_debug("remove\n"); 4621da177e4SLinus Torvalds unlink_clip_vcc(clip_vcc); 4631da177e4SLinus Torvalds return 0; 4641da177e4SLinus Torvalds } 46578fbfd8aSDavid S. Miller rt = ip_route_output(&init_net, ip, 0, 1, 0); 466b23dd4feSDavid S. Miller if (IS_ERR(rt)) 467b23dd4feSDavid S. Miller return PTR_ERR(rt); 46832092ecfSDavid Miller neigh = __neigh_lookup(&arp_tbl, &ip, rt->dst.dev, 1); 4691da177e4SLinus Torvalds ip_rt_put(rt); 4701da177e4SLinus Torvalds if (!neigh) 4711da177e4SLinus Torvalds return -ENOMEM; 472869759b9SDavid Miller entry = neighbour_priv(neigh); 4731da177e4SLinus Torvalds if (entry != clip_vcc->entry) { 474e49e76dbSStephen Hemminger if (!clip_vcc->entry) 47599824461SJoe Perches pr_debug("add\n"); 4761da177e4SLinus Torvalds else { 47799824461SJoe Perches pr_debug("update\n"); 4781da177e4SLinus Torvalds unlink_clip_vcc(clip_vcc); 4791da177e4SLinus Torvalds } 4801da177e4SLinus Torvalds link_vcc(clip_vcc, entry); 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds error = neigh_update(neigh, llc_oui, NUD_PERMANENT, 4837b8f7a40SRoopa Prabhu NEIGH_UPDATE_F_OVERRIDE | NEIGH_UPDATE_F_ADMIN, 0); 4841da177e4SLinus Torvalds neigh_release(neigh); 4851da177e4SLinus Torvalds return error; 4861da177e4SLinus Torvalds } 4871da177e4SLinus Torvalds 488dde09758SStephen Hemminger static const struct net_device_ops clip_netdev_ops = { 489dde09758SStephen Hemminger .ndo_start_xmit = clip_start_xmit, 49032092ecfSDavid Miller .ndo_neigh_construct = clip_constructor, 491dde09758SStephen Hemminger }; 492dde09758SStephen Hemminger 4931da177e4SLinus Torvalds static void clip_setup(struct net_device *dev) 4941da177e4SLinus Torvalds { 495dde09758SStephen Hemminger dev->netdev_ops = &clip_netdev_ops; 4961da177e4SLinus Torvalds dev->type = ARPHRD_ATM; 497596b9b68SDavid Miller dev->neigh_priv_len = sizeof(struct atmarp_entry); 4981da177e4SLinus Torvalds dev->hard_header_len = RFC1483LLC_LEN; 4991da177e4SLinus Torvalds dev->mtu = RFC1626_MTU; 5001da177e4SLinus Torvalds dev->tx_queue_len = 100; /* "normal" queue (packets) */ 5011da177e4SLinus Torvalds /* When using a "real" qdisc, the qdisc determines the queue */ 5021da177e4SLinus Torvalds /* length. tx_queue_len is only used for the default case, */ 5031da177e4SLinus Torvalds /* without any more elaborate queuing. 100 is a reasonable */ 5041da177e4SLinus Torvalds /* compromise between decent burst-tolerance and protection */ 5051da177e4SLinus Torvalds /* against memory hogs. */ 50602875878SEric Dumazet netif_keep_dst(dev); 5071da177e4SLinus Torvalds } 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds static int clip_create(int number) 5101da177e4SLinus Torvalds { 5111da177e4SLinus Torvalds struct net_device *dev; 5121da177e4SLinus Torvalds struct clip_priv *clip_priv; 5131da177e4SLinus Torvalds int error; 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds if (number != -1) { 5161da177e4SLinus Torvalds for (dev = clip_devs; dev; dev = PRIV(dev)->next) 517e49e76dbSStephen Hemminger if (PRIV(dev)->number == number) 518e49e76dbSStephen Hemminger return -EEXIST; 519e49e76dbSStephen Hemminger } else { 5201da177e4SLinus Torvalds number = 0; 5211da177e4SLinus Torvalds for (dev = clip_devs; dev; dev = PRIV(dev)->next) 5221da177e4SLinus Torvalds if (PRIV(dev)->number >= number) 5231da177e4SLinus Torvalds number = PRIV(dev)->number + 1; 5241da177e4SLinus Torvalds } 525c835a677STom Gundersen dev = alloc_netdev(sizeof(struct clip_priv), "", NET_NAME_UNKNOWN, 526c835a677STom Gundersen clip_setup); 5271da177e4SLinus Torvalds if (!dev) 5281da177e4SLinus Torvalds return -ENOMEM; 5291da177e4SLinus Torvalds clip_priv = PRIV(dev); 5301da177e4SLinus Torvalds sprintf(dev->name, "atm%d", number); 5311da177e4SLinus Torvalds spin_lock_init(&clip_priv->xoff_lock); 5321da177e4SLinus Torvalds clip_priv->number = number; 5331da177e4SLinus Torvalds error = register_netdev(dev); 5341da177e4SLinus Torvalds if (error) { 5351da177e4SLinus Torvalds free_netdev(dev); 5361da177e4SLinus Torvalds return error; 5371da177e4SLinus Torvalds } 5381da177e4SLinus Torvalds clip_priv->next = clip_devs; 5391da177e4SLinus Torvalds clip_devs = dev; 54052240062SStephen Hemminger pr_debug("registered (net:%s)\n", dev->name); 5411da177e4SLinus Torvalds return number; 5421da177e4SLinus Torvalds } 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds static int clip_device_event(struct notifier_block *this, unsigned long event, 545351638e7SJiri Pirko void *ptr) 5461da177e4SLinus Torvalds { 547351638e7SJiri Pirko struct net_device *dev = netdev_notifier_info_to_dev(ptr); 548f3a0592bSStephen Hemminger 549721499e8SYOSHIFUJI Hideaki if (!net_eq(dev_net(dev), &init_net)) 550e9dc8653SEric W. Biederman return NOTIFY_DONE; 551e9dc8653SEric W. Biederman 55232092ecfSDavid Miller if (event == NETDEV_UNREGISTER) 5531da177e4SLinus Torvalds return NOTIFY_DONE; 554f3a0592bSStephen Hemminger 555f3a0592bSStephen Hemminger /* ignore non-CLIP devices */ 556dde09758SStephen Hemminger if (dev->type != ARPHRD_ATM || dev->netdev_ops != &clip_netdev_ops) 557f3a0592bSStephen Hemminger return NOTIFY_DONE; 558f3a0592bSStephen Hemminger 5591da177e4SLinus Torvalds switch (event) { 5601da177e4SLinus Torvalds case NETDEV_UP: 56199824461SJoe Perches pr_debug("NETDEV_UP\n"); 5625ff765f3SStephen Hemminger to_atmarpd(act_up, PRIV(dev)->number, 0); 5631da177e4SLinus Torvalds break; 5641da177e4SLinus Torvalds case NETDEV_GOING_DOWN: 56599824461SJoe Perches pr_debug("NETDEV_DOWN\n"); 5665ff765f3SStephen Hemminger to_atmarpd(act_down, PRIV(dev)->number, 0); 5671da177e4SLinus Torvalds break; 5681da177e4SLinus Torvalds case NETDEV_CHANGE: 5691da177e4SLinus Torvalds case NETDEV_CHANGEMTU: 57099824461SJoe Perches pr_debug("NETDEV_CHANGE*\n"); 5715ff765f3SStephen Hemminger to_atmarpd(act_change, PRIV(dev)->number, 0); 5721da177e4SLinus Torvalds break; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds return NOTIFY_DONE; 5751da177e4SLinus Torvalds } 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds static int clip_inet_event(struct notifier_block *this, unsigned long event, 5781da177e4SLinus Torvalds void *ifa) 5791da177e4SLinus Torvalds { 5801da177e4SLinus Torvalds struct in_device *in_dev; 58175538c2bSCong Wang struct netdev_notifier_info info; 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds in_dev = ((struct in_ifaddr *)ifa)->ifa_dev; 5841da177e4SLinus Torvalds /* 5851da177e4SLinus Torvalds * Transitions are of the down-change-up type, so it's sufficient to 5861da177e4SLinus Torvalds * handle the change on up. 5871da177e4SLinus Torvalds */ 588e49e76dbSStephen Hemminger if (event != NETDEV_UP) 589e49e76dbSStephen Hemminger return NOTIFY_DONE; 59075538c2bSCong Wang netdev_notifier_info_init(&info, in_dev->dev); 59175538c2bSCong Wang return clip_device_event(this, NETDEV_CHANGE, &info); 5921da177e4SLinus Torvalds } 5931da177e4SLinus Torvalds 5941da177e4SLinus Torvalds static struct notifier_block clip_dev_notifier = { 5955ff765f3SStephen Hemminger .notifier_call = clip_device_event, 5961da177e4SLinus Torvalds }; 5971da177e4SLinus Torvalds 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds static struct notifier_block clip_inet_notifier = { 6015ff765f3SStephen Hemminger .notifier_call = clip_inet_event, 6021da177e4SLinus Torvalds }; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds static void atmarpd_close(struct atm_vcc *vcc) 6071da177e4SLinus Torvalds { 60899824461SJoe Perches pr_debug("\n"); 609f3a0592bSStephen Hemminger 610f3a0592bSStephen Hemminger rtnl_lock(); 611f3a0592bSStephen Hemminger atmarpd = NULL; 6121da177e4SLinus Torvalds skb_queue_purge(&sk_atm(vcc)->sk_receive_queue); 613f3a0592bSStephen Hemminger rtnl_unlock(); 614f3a0592bSStephen Hemminger 61552240062SStephen Hemminger pr_debug("(done)\n"); 6161da177e4SLinus Torvalds module_put(THIS_MODULE); 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds 619800bb47eSBhumika Goyal static const struct atmdev_ops atmarpd_dev_ops = { 6201da177e4SLinus Torvalds .close = atmarpd_close 6211da177e4SLinus Torvalds }; 6221da177e4SLinus Torvalds 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds static struct atm_dev atmarpd_dev = { 6251da177e4SLinus Torvalds .ops = &atmarpd_dev_ops, 6261da177e4SLinus Torvalds .type = "arpd", 6271da177e4SLinus Torvalds .number = 999, 6284ef8d0aeSMilind Arun Choudhary .lock = __SPIN_LOCK_UNLOCKED(atmarpd_dev.lock) 6291da177e4SLinus Torvalds }; 6301da177e4SLinus Torvalds 6311da177e4SLinus Torvalds 6321da177e4SLinus Torvalds static int atm_init_atmarp(struct atm_vcc *vcc) 6331da177e4SLinus Torvalds { 634f3a0592bSStephen Hemminger rtnl_lock(); 635f3a0592bSStephen Hemminger if (atmarpd) { 636f3a0592bSStephen Hemminger rtnl_unlock(); 637f3a0592bSStephen Hemminger return -EADDRINUSE; 638f3a0592bSStephen Hemminger } 639f3a0592bSStephen Hemminger 6402d907392SStephen Hemminger mod_timer(&idle_timer, jiffies + CLIP_CHECK_INTERVAL * HZ); 6412d907392SStephen Hemminger 6421da177e4SLinus Torvalds atmarpd = vcc; 6431da177e4SLinus Torvalds set_bit(ATM_VF_META, &vcc->flags); 6441da177e4SLinus Torvalds set_bit(ATM_VF_READY, &vcc->flags); 6451da177e4SLinus Torvalds /* allow replies and avoid getting closed if signaling dies */ 6461da177e4SLinus Torvalds vcc->dev = &atmarpd_dev; 6471da177e4SLinus Torvalds vcc_insert_socket(sk_atm(vcc)); 6481da177e4SLinus Torvalds vcc->push = NULL; 6491da177e4SLinus Torvalds vcc->pop = NULL; /* crash */ 6501da177e4SLinus Torvalds vcc->push_oam = NULL; /* crash */ 651f3a0592bSStephen Hemminger rtnl_unlock(); 6521da177e4SLinus Torvalds return 0; 6531da177e4SLinus Torvalds } 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds static int clip_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 6561da177e4SLinus Torvalds { 6571da177e4SLinus Torvalds struct atm_vcc *vcc = ATM_SD(sock); 6581da177e4SLinus Torvalds int err = 0; 6591da177e4SLinus Torvalds 6601da177e4SLinus Torvalds switch (cmd) { 6611da177e4SLinus Torvalds case SIOCMKCLIP: 6621da177e4SLinus Torvalds case ATMARPD_CTRL: 6631da177e4SLinus Torvalds case ATMARP_MKIP: 6641da177e4SLinus Torvalds case ATMARP_SETENTRY: 6651da177e4SLinus Torvalds case ATMARP_ENCAP: 6661da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) 6671da177e4SLinus Torvalds return -EPERM; 6681da177e4SLinus Torvalds break; 6691da177e4SLinus Torvalds default: 6701da177e4SLinus Torvalds return -ENOIOCTLCMD; 6711da177e4SLinus Torvalds } 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds switch (cmd) { 6741da177e4SLinus Torvalds case SIOCMKCLIP: 6751da177e4SLinus Torvalds err = clip_create(arg); 6761da177e4SLinus Torvalds break; 6771da177e4SLinus Torvalds case ATMARPD_CTRL: 6781da177e4SLinus Torvalds err = atm_init_atmarp(vcc); 6791da177e4SLinus Torvalds if (!err) { 6801da177e4SLinus Torvalds sock->state = SS_CONNECTED; 6811da177e4SLinus Torvalds __module_get(THIS_MODULE); 6821da177e4SLinus Torvalds } 6831da177e4SLinus Torvalds break; 6841da177e4SLinus Torvalds case ATMARP_MKIP: 6851da177e4SLinus Torvalds err = clip_mkip(vcc, arg); 6861da177e4SLinus Torvalds break; 6871da177e4SLinus Torvalds case ATMARP_SETENTRY: 68830d492daSAl Viro err = clip_setentry(vcc, (__force __be32)arg); 6891da177e4SLinus Torvalds break; 6901da177e4SLinus Torvalds case ATMARP_ENCAP: 6911da177e4SLinus Torvalds err = clip_encap(vcc, arg); 6921da177e4SLinus Torvalds break; 6931da177e4SLinus Torvalds } 6941da177e4SLinus Torvalds return err; 6951da177e4SLinus Torvalds } 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds static struct atm_ioctl clip_ioctl_ops = { 6981da177e4SLinus Torvalds .owner = THIS_MODULE, 6991da177e4SLinus Torvalds .ioctl = clip_ioctl, 7001da177e4SLinus Torvalds }; 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 7031da177e4SLinus Torvalds 7041da177e4SLinus Torvalds static void svc_addr(struct seq_file *seq, struct sockaddr_atmsvc *addr) 7051da177e4SLinus Torvalds { 7061da177e4SLinus Torvalds static int code[] = { 1, 2, 10, 6, 1, 0 }; 7071da177e4SLinus Torvalds static int e164[] = { 1, 8, 4, 6, 1, 0 }; 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds if (*addr->sas_addr.pub) { 7101da177e4SLinus Torvalds seq_printf(seq, "%s", addr->sas_addr.pub); 7111da177e4SLinus Torvalds if (*addr->sas_addr.prv) 7121da177e4SLinus Torvalds seq_putc(seq, '+'); 7131da177e4SLinus Torvalds } else if (!*addr->sas_addr.prv) { 7141da177e4SLinus Torvalds seq_printf(seq, "%s", "(none)"); 7151da177e4SLinus Torvalds return; 7161da177e4SLinus Torvalds } 7171da177e4SLinus Torvalds if (*addr->sas_addr.prv) { 7181da177e4SLinus Torvalds unsigned char *prv = addr->sas_addr.prv; 7191da177e4SLinus Torvalds int *fields; 7201da177e4SLinus Torvalds int i, j; 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds fields = *prv == ATM_AFI_E164 ? e164 : code; 7231da177e4SLinus Torvalds for (i = 0; fields[i]; i++) { 7241da177e4SLinus Torvalds for (j = fields[i]; j; j--) 7251da177e4SLinus Torvalds seq_printf(seq, "%02X", *prv++); 7261da177e4SLinus Torvalds if (fields[i + 1]) 7271da177e4SLinus Torvalds seq_putc(seq, '.'); 7281da177e4SLinus Torvalds } 7291da177e4SLinus Torvalds } 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* This means the neighbour entry has no attached VCC objects. */ 7331da177e4SLinus Torvalds #define SEQ_NO_VCC_TOKEN ((void *) 2) 7341da177e4SLinus Torvalds 735869759b9SDavid Miller static void atmarp_info(struct seq_file *seq, struct neighbour *n, 7361da177e4SLinus Torvalds struct atmarp_entry *entry, struct clip_vcc *clip_vcc) 7371da177e4SLinus Torvalds { 738869759b9SDavid Miller struct net_device *dev = n->dev; 7391da177e4SLinus Torvalds unsigned long exp; 7401da177e4SLinus Torvalds char buf[17]; 7411da177e4SLinus Torvalds int svc, llc, off; 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds svc = ((clip_vcc == SEQ_NO_VCC_TOKEN) || 7441da177e4SLinus Torvalds (sk_atm(clip_vcc->vcc)->sk_family == AF_ATMSVC)); 7451da177e4SLinus Torvalds 746e49e76dbSStephen Hemminger llc = ((clip_vcc == SEQ_NO_VCC_TOKEN) || clip_vcc->encap); 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds if (clip_vcc == SEQ_NO_VCC_TOKEN) 7491da177e4SLinus Torvalds exp = entry->neigh->used; 7501da177e4SLinus Torvalds else 7511da177e4SLinus Torvalds exp = clip_vcc->last_use; 7521da177e4SLinus Torvalds 7531da177e4SLinus Torvalds exp = (jiffies - exp) / HZ; 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds seq_printf(seq, "%-6s%-4s%-4s%5ld ", 756e49e76dbSStephen Hemminger dev->name, svc ? "SVC" : "PVC", llc ? "LLC" : "NULL", exp); 7571da177e4SLinus Torvalds 758869759b9SDavid Miller off = scnprintf(buf, sizeof(buf) - 1, "%pI4", n->primary_key); 7591da177e4SLinus Torvalds while (off < 16) 7601da177e4SLinus Torvalds buf[off++] = ' '; 7611da177e4SLinus Torvalds buf[off] = '\0'; 7621da177e4SLinus Torvalds seq_printf(seq, "%s", buf); 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds if (clip_vcc == SEQ_NO_VCC_TOKEN) { 7651da177e4SLinus Torvalds if (time_before(jiffies, entry->expires)) 7661da177e4SLinus Torvalds seq_printf(seq, "(resolving)\n"); 7671da177e4SLinus Torvalds else 7681da177e4SLinus Torvalds seq_printf(seq, "(expired, ref %d)\n", 7699f237430SReshetova, Elena refcount_read(&entry->neigh->refcnt)); 7701da177e4SLinus Torvalds } else if (!svc) { 7711da177e4SLinus Torvalds seq_printf(seq, "%d.%d.%d\n", 7721da177e4SLinus Torvalds clip_vcc->vcc->dev->number, 773e49e76dbSStephen Hemminger clip_vcc->vcc->vpi, clip_vcc->vcc->vci); 7741da177e4SLinus Torvalds } else { 7751da177e4SLinus Torvalds svc_addr(seq, &clip_vcc->vcc->remote); 7761da177e4SLinus Torvalds seq_putc(seq, '\n'); 7771da177e4SLinus Torvalds } 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds struct clip_seq_state { 7811da177e4SLinus Torvalds /* This member must be first. */ 7821da177e4SLinus Torvalds struct neigh_seq_state ns; 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds /* Local to clip specific iteration. */ 7851da177e4SLinus Torvalds struct clip_vcc *vcc; 7861da177e4SLinus Torvalds }; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds static struct clip_vcc *clip_seq_next_vcc(struct atmarp_entry *e, 7891da177e4SLinus Torvalds struct clip_vcc *curr) 7901da177e4SLinus Torvalds { 7911da177e4SLinus Torvalds if (!curr) { 7921da177e4SLinus Torvalds curr = e->vccs; 7931da177e4SLinus Torvalds if (!curr) 7941da177e4SLinus Torvalds return SEQ_NO_VCC_TOKEN; 7951da177e4SLinus Torvalds return curr; 7961da177e4SLinus Torvalds } 7971da177e4SLinus Torvalds if (curr == SEQ_NO_VCC_TOKEN) 7981da177e4SLinus Torvalds return NULL; 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds curr = curr->next; 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds return curr; 8031da177e4SLinus Torvalds } 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds static void *clip_seq_vcc_walk(struct clip_seq_state *state, 8061da177e4SLinus Torvalds struct atmarp_entry *e, loff_t * pos) 8071da177e4SLinus Torvalds { 8081da177e4SLinus Torvalds struct clip_vcc *vcc = state->vcc; 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds vcc = clip_seq_next_vcc(e, vcc); 8111da177e4SLinus Torvalds if (vcc && pos != NULL) { 8121da177e4SLinus Torvalds while (*pos) { 8131da177e4SLinus Torvalds vcc = clip_seq_next_vcc(e, vcc); 8141da177e4SLinus Torvalds if (!vcc) 8151da177e4SLinus Torvalds break; 8161da177e4SLinus Torvalds --(*pos); 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds } 8191da177e4SLinus Torvalds state->vcc = vcc; 8201da177e4SLinus Torvalds 8211da177e4SLinus Torvalds return vcc; 8221da177e4SLinus Torvalds } 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds static void *clip_seq_sub_iter(struct neigh_seq_state *_state, 8251da177e4SLinus Torvalds struct neighbour *n, loff_t * pos) 8261da177e4SLinus Torvalds { 8271da177e4SLinus Torvalds struct clip_seq_state *state = (struct clip_seq_state *)_state; 8281da177e4SLinus Torvalds 82932092ecfSDavid Miller if (n->dev->type != ARPHRD_ATM) 83032092ecfSDavid Miller return NULL; 83132092ecfSDavid Miller 832869759b9SDavid Miller return clip_seq_vcc_walk(state, neighbour_priv(n), pos); 8331da177e4SLinus Torvalds } 8341da177e4SLinus Torvalds 8351da177e4SLinus Torvalds static void *clip_seq_start(struct seq_file *seq, loff_t * pos) 8361da177e4SLinus Torvalds { 837ae22120aSDenis V. Lunev struct clip_seq_state *state = seq->private; 838ae22120aSDenis V. Lunev state->ns.neigh_sub_iter = clip_seq_sub_iter; 83932092ecfSDavid Miller return neigh_seq_start(seq, pos, &arp_tbl, NEIGH_SEQ_NEIGH_ONLY); 8401da177e4SLinus Torvalds } 8411da177e4SLinus Torvalds 8421da177e4SLinus Torvalds static int clip_seq_show(struct seq_file *seq, void *v) 8431da177e4SLinus Torvalds { 8441da177e4SLinus Torvalds static char atm_arp_banner[] = 8451da177e4SLinus Torvalds "IPitf TypeEncp Idle IP address ATM address\n"; 8461da177e4SLinus Torvalds 8471da177e4SLinus Torvalds if (v == SEQ_START_TOKEN) { 8481da177e4SLinus Torvalds seq_puts(seq, atm_arp_banner); 8491da177e4SLinus Torvalds } else { 8501da177e4SLinus Torvalds struct clip_seq_state *state = seq->private; 8511da177e4SLinus Torvalds struct clip_vcc *vcc = state->vcc; 852869759b9SDavid Miller struct neighbour *n = v; 8531da177e4SLinus Torvalds 854869759b9SDavid Miller atmarp_info(seq, n, neighbour_priv(n), vcc); 8551da177e4SLinus Torvalds } 8561da177e4SLinus Torvalds return 0; 8571da177e4SLinus Torvalds } 8581da177e4SLinus Torvalds 85956b3d975SPhilippe De Muyter static const struct seq_operations arp_seq_ops = { 8601da177e4SLinus Torvalds .start = clip_seq_start, 8611da177e4SLinus Torvalds .next = neigh_seq_next, 8621da177e4SLinus Torvalds .stop = neigh_seq_stop, 8631da177e4SLinus Torvalds .show = clip_seq_show, 8641da177e4SLinus Torvalds }; 8651da177e4SLinus Torvalds #endif 8661da177e4SLinus Torvalds 867dbee0d3fSWang Chen static void atm_clip_exit_noproc(void); 868dbee0d3fSWang Chen 8691da177e4SLinus Torvalds static int __init atm_clip_init(void) 8701da177e4SLinus Torvalds { 8711da177e4SLinus Torvalds register_atm_ioctl(&clip_ioctl_ops); 872f3a0592bSStephen Hemminger register_netdevice_notifier(&clip_dev_notifier); 873f3a0592bSStephen Hemminger register_inetaddr_notifier(&clip_inet_notifier); 8741da177e4SLinus Torvalds 875ba421793SKees Cook timer_setup(&idle_timer, idle_timer_check, 0); 8762d907392SStephen Hemminger 87724781734SAdrian Bunk #ifdef CONFIG_PROC_FS 87824781734SAdrian Bunk { 87924781734SAdrian Bunk struct proc_dir_entry *p; 88024781734SAdrian Bunk 881c3506372SChristoph Hellwig p = proc_create_net("arp", 0444, atm_proc_root, &arp_seq_ops, 882c3506372SChristoph Hellwig sizeof(struct clip_seq_state)); 883dbee0d3fSWang Chen if (!p) { 88499824461SJoe Perches pr_err("Unable to initialize /proc/net/atm/arp\n"); 885dbee0d3fSWang Chen atm_clip_exit_noproc(); 886dbee0d3fSWang Chen return -ENOMEM; 887dbee0d3fSWang Chen } 88824781734SAdrian Bunk } 88924781734SAdrian Bunk #endif 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds return 0; 8921da177e4SLinus Torvalds } 8931da177e4SLinus Torvalds 894dbee0d3fSWang Chen static void atm_clip_exit_noproc(void) 8951da177e4SLinus Torvalds { 8961da177e4SLinus Torvalds struct net_device *dev, *next; 8971da177e4SLinus Torvalds 898f3a0592bSStephen Hemminger unregister_inetaddr_notifier(&clip_inet_notifier); 899f3a0592bSStephen Hemminger unregister_netdevice_notifier(&clip_dev_notifier); 900f3a0592bSStephen Hemminger 9011da177e4SLinus Torvalds deregister_atm_ioctl(&clip_ioctl_ops); 9021da177e4SLinus Torvalds 9031da177e4SLinus Torvalds /* First, stop the idle timer, so it stops banging 9041da177e4SLinus Torvalds * on the table. 9051da177e4SLinus Torvalds */ 9062d907392SStephen Hemminger del_timer_sync(&idle_timer); 9071da177e4SLinus Torvalds 9081da177e4SLinus Torvalds dev = clip_devs; 9091da177e4SLinus Torvalds while (dev) { 9101da177e4SLinus Torvalds next = PRIV(dev)->next; 9111da177e4SLinus Torvalds unregister_netdev(dev); 9121da177e4SLinus Torvalds free_netdev(dev); 9131da177e4SLinus Torvalds dev = next; 9141da177e4SLinus Torvalds } 9151da177e4SLinus Torvalds } 9161da177e4SLinus Torvalds 917dbee0d3fSWang Chen static void __exit atm_clip_exit(void) 918dbee0d3fSWang Chen { 919dbee0d3fSWang Chen remove_proc_entry("arp", atm_proc_root); 920dbee0d3fSWang Chen 921dbee0d3fSWang Chen atm_clip_exit_noproc(); 922dbee0d3fSWang Chen } 923dbee0d3fSWang Chen 9241da177e4SLinus Torvalds module_init(atm_clip_init); 9251da177e4SLinus Torvalds module_exit(atm_clip_exit); 9264909e488SStephen Hemminger MODULE_AUTHOR("Werner Almesberger"); 9274909e488SStephen Hemminger MODULE_DESCRIPTION("Classical/IP over ATM interface"); 9281da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 929