109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /* net/atm/clip.c - RFC1577 Classical IP over ATM */
31da177e4SLinus Torvalds
41da177e4SLinus Torvalds /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
51da177e4SLinus Torvalds
699824461SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
799824461SJoe Perches
81da177e4SLinus Torvalds #include <linux/string.h>
91da177e4SLinus Torvalds #include <linux/errno.h>
101da177e4SLinus Torvalds #include <linux/kernel.h> /* for UINT_MAX */
111da177e4SLinus Torvalds #include <linux/module.h>
121da177e4SLinus Torvalds #include <linux/init.h>
131da177e4SLinus Torvalds #include <linux/netdevice.h>
141da177e4SLinus Torvalds #include <linux/skbuff.h>
151da177e4SLinus Torvalds #include <linux/wait.h>
161da177e4SLinus Torvalds #include <linux/timer.h>
171da177e4SLinus Torvalds #include <linux/if_arp.h> /* for some manifest constants */
181da177e4SLinus Torvalds #include <linux/notifier.h>
191da177e4SLinus Torvalds #include <linux/atm.h>
201da177e4SLinus Torvalds #include <linux/atmdev.h>
211da177e4SLinus Torvalds #include <linux/atmclip.h>
221da177e4SLinus Torvalds #include <linux/atmarp.h>
234fc268d2SRandy Dunlap #include <linux/capability.h>
241da177e4SLinus Torvalds #include <linux/ip.h> /* for net/route.h */
251da177e4SLinus Torvalds #include <linux/in.h> /* for struct sockaddr_in */
261da177e4SLinus Torvalds #include <linux/if.h> /* for IFF_UP */
271da177e4SLinus Torvalds #include <linux/inetdevice.h>
281da177e4SLinus Torvalds #include <linux/bitops.h>
294bdbf6c0SRandy Dunlap #include <linux/poison.h>
301da177e4SLinus Torvalds #include <linux/proc_fs.h>
311da177e4SLinus Torvalds #include <linux/seq_file.h>
321da177e4SLinus Torvalds #include <linux/rcupdate.h>
331da177e4SLinus Torvalds #include <linux/jhash.h>
345a0e3ad6STejun Heo #include <linux/slab.h>
351da177e4SLinus Torvalds #include <net/route.h> /* for struct rtable and routing */
361da177e4SLinus Torvalds #include <net/icmp.h> /* icmp_send */
3732092ecfSDavid Miller #include <net/arp.h>
38e956ea1bSJoe Perches #include <linux/param.h> /* for HZ */
39e956ea1bSJoe Perches #include <linux/uaccess.h>
401da177e4SLinus Torvalds #include <asm/byteorder.h> /* for htons etc. */
4160063497SArun Sharma #include <linux/atomic.h>
421da177e4SLinus Torvalds
431da177e4SLinus Torvalds #include "common.h"
441da177e4SLinus Torvalds #include "resources.h"
451da177e4SLinus Torvalds #include <net/atmclip.h>
461da177e4SLinus Torvalds
471da177e4SLinus Torvalds static struct net_device *clip_devs;
481da177e4SLinus Torvalds static struct atm_vcc *atmarpd;
491da177e4SLinus Torvalds static struct timer_list idle_timer;
50597cdbc2SEric Dumazet static const struct neigh_ops clip_neigh_ops;
511da177e4SLinus Torvalds
to_atmarpd(enum atmarp_ctrl_type type,int itf,__be32 ip)5230d492daSAl Viro static int to_atmarpd(enum atmarp_ctrl_type type, int itf, __be32 ip)
531da177e4SLinus Torvalds {
541da177e4SLinus Torvalds struct sock *sk;
551da177e4SLinus Torvalds struct atmarp_ctrl *ctrl;
561da177e4SLinus Torvalds struct sk_buff *skb;
571da177e4SLinus Torvalds
5899824461SJoe Perches pr_debug("(%d)\n", type);
59e49e76dbSStephen Hemminger if (!atmarpd)
60e49e76dbSStephen Hemminger return -EUNATCH;
611da177e4SLinus Torvalds skb = alloc_skb(sizeof(struct atmarp_ctrl), GFP_ATOMIC);
62e49e76dbSStephen Hemminger if (!skb)
63e49e76dbSStephen Hemminger return -ENOMEM;
644df864c1SJohannes Berg ctrl = skb_put(skb, sizeof(struct atmarp_ctrl));
651da177e4SLinus Torvalds ctrl->type = type;
661da177e4SLinus Torvalds ctrl->itf_num = itf;
671da177e4SLinus Torvalds ctrl->ip = ip;
681da177e4SLinus Torvalds atm_force_charge(atmarpd, skb->truesize);
691da177e4SLinus Torvalds
701da177e4SLinus Torvalds sk = sk_atm(atmarpd);
711da177e4SLinus Torvalds skb_queue_tail(&sk->sk_receive_queue, skb);
72676d2369SDavid S. Miller sk->sk_data_ready(sk);
731da177e4SLinus Torvalds return 0;
741da177e4SLinus Torvalds }
751da177e4SLinus Torvalds
link_vcc(struct clip_vcc * clip_vcc,struct atmarp_entry * entry)761da177e4SLinus Torvalds static void link_vcc(struct clip_vcc *clip_vcc, struct atmarp_entry *entry)
771da177e4SLinus Torvalds {
7899824461SJoe Perches pr_debug("%p to entry %p (neigh %p)\n", clip_vcc, entry, entry->neigh);
791da177e4SLinus Torvalds clip_vcc->entry = entry;
801da177e4SLinus Torvalds clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */
811da177e4SLinus Torvalds clip_vcc->next = entry->vccs;
821da177e4SLinus Torvalds entry->vccs = clip_vcc;
831da177e4SLinus Torvalds entry->neigh->used = jiffies;
841da177e4SLinus Torvalds }
851da177e4SLinus Torvalds
unlink_clip_vcc(struct clip_vcc * clip_vcc)861da177e4SLinus Torvalds static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds struct atmarp_entry *entry = clip_vcc->entry;
891da177e4SLinus Torvalds struct clip_vcc **walk;
901da177e4SLinus Torvalds
911da177e4SLinus Torvalds if (!entry) {
92*60f5c4aaSAditya Pakki pr_err("!clip_vcc->entry (clip_vcc %p)\n", clip_vcc);
931da177e4SLinus Torvalds return;
941da177e4SLinus Torvalds }
95932ff279SHerbert Xu netif_tx_lock_bh(entry->neigh->dev); /* block clip_start_xmit() */
961da177e4SLinus Torvalds entry->neigh->used = jiffies;
971da177e4SLinus Torvalds for (walk = &entry->vccs; *walk; walk = &(*walk)->next)
981da177e4SLinus Torvalds if (*walk == clip_vcc) {
991da177e4SLinus Torvalds int error;
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvalds *walk = clip_vcc->next; /* atomic */
1021da177e4SLinus Torvalds clip_vcc->entry = NULL;
1031da177e4SLinus Torvalds if (clip_vcc->xoff)
1041da177e4SLinus Torvalds netif_wake_queue(entry->neigh->dev);
1051da177e4SLinus Torvalds if (entry->vccs)
1061da177e4SLinus Torvalds goto out;
1071da177e4SLinus Torvalds entry->expires = jiffies - 1;
1081da177e4SLinus Torvalds /* force resolution or expiration */
1091da177e4SLinus Torvalds error = neigh_update(entry->neigh, NULL, NUD_NONE,
1107b8f7a40SRoopa Prabhu NEIGH_UPDATE_F_ADMIN, 0);
1111da177e4SLinus Torvalds if (error)
112*60f5c4aaSAditya Pakki pr_err("neigh_update failed with %d\n", error);
1131da177e4SLinus Torvalds goto out;
1141da177e4SLinus Torvalds }
115*60f5c4aaSAditya Pakki pr_err("ATMARP: failed (entry %p, vcc 0x%p)\n", entry, clip_vcc);
1161da177e4SLinus Torvalds out:
117932ff279SHerbert Xu netif_tx_unlock_bh(entry->neigh->dev);
1181da177e4SLinus Torvalds }
1191da177e4SLinus Torvalds
1201da177e4SLinus Torvalds /* The neighbour entry n->lock is held. */
neigh_check_cb(struct neighbour * n)1211da177e4SLinus Torvalds static int neigh_check_cb(struct neighbour *n)
1221da177e4SLinus Torvalds {
123869759b9SDavid Miller struct atmarp_entry *entry = neighbour_priv(n);
1241da177e4SLinus Torvalds struct clip_vcc *cv;
1251da177e4SLinus Torvalds
126597cdbc2SEric Dumazet if (n->ops != &clip_neigh_ops)
127597cdbc2SEric Dumazet return 0;
1281da177e4SLinus Torvalds for (cv = entry->vccs; cv; cv = cv->next) {
1291da177e4SLinus Torvalds unsigned long exp = cv->last_use + cv->idle_timeout;
1301da177e4SLinus Torvalds
1311da177e4SLinus Torvalds if (cv->idle_timeout && time_after(jiffies, exp)) {
13252240062SStephen Hemminger pr_debug("releasing vcc %p->%p of entry %p\n",
1331da177e4SLinus Torvalds cv, cv->vcc, entry);
1341da177e4SLinus Torvalds vcc_release_async(cv->vcc, -ETIMEDOUT);
1351da177e4SLinus Torvalds }
1361da177e4SLinus Torvalds }
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvalds if (entry->vccs || time_before(jiffies, entry->expires))
1391da177e4SLinus Torvalds return 0;
1401da177e4SLinus Torvalds
1419f237430SReshetova, Elena if (refcount_read(&n->refcnt) > 1) {
1421da177e4SLinus Torvalds struct sk_buff *skb;
1431da177e4SLinus Torvalds
14452240062SStephen Hemminger pr_debug("destruction postponed with ref %d\n",
1459f237430SReshetova, Elena refcount_read(&n->refcnt));
1461da177e4SLinus Torvalds
1471da177e4SLinus Torvalds while ((skb = skb_dequeue(&n->arp_queue)) != NULL)
1481da177e4SLinus Torvalds dev_kfree_skb(skb);
1491da177e4SLinus Torvalds
1501da177e4SLinus Torvalds return 0;
1511da177e4SLinus Torvalds }
1521da177e4SLinus Torvalds
15352240062SStephen Hemminger pr_debug("expired neigh %p\n", n);
1541da177e4SLinus Torvalds return 1;
1551da177e4SLinus Torvalds }
1561da177e4SLinus Torvalds
idle_timer_check(struct timer_list * unused)157ba421793SKees Cook static void idle_timer_check(struct timer_list *unused)
1581da177e4SLinus Torvalds {
159597cdbc2SEric Dumazet write_lock(&arp_tbl.lock);
160597cdbc2SEric Dumazet __neigh_for_each_release(&arp_tbl, neigh_check_cb);
1611da177e4SLinus Torvalds mod_timer(&idle_timer, jiffies + CLIP_CHECK_INTERVAL * HZ);
162597cdbc2SEric Dumazet write_unlock(&arp_tbl.lock);
1631da177e4SLinus Torvalds }
1641da177e4SLinus Torvalds
clip_arp_rcv(struct sk_buff * skb)1651da177e4SLinus Torvalds static int clip_arp_rcv(struct sk_buff *skb)
1661da177e4SLinus Torvalds {
1671da177e4SLinus Torvalds struct atm_vcc *vcc;
1681da177e4SLinus Torvalds
16999824461SJoe Perches pr_debug("\n");
1701da177e4SLinus Torvalds vcc = ATM_SKB(skb)->vcc;
1711da177e4SLinus Torvalds if (!vcc || !atm_charge(vcc, skb->truesize)) {
1721da177e4SLinus Torvalds dev_kfree_skb_any(skb);
1731da177e4SLinus Torvalds return 0;
1741da177e4SLinus Torvalds }
17552240062SStephen Hemminger pr_debug("pushing to %p\n", vcc);
17652240062SStephen Hemminger pr_debug("using %p\n", CLIP_VCC(vcc)->old_push);
1771da177e4SLinus Torvalds CLIP_VCC(vcc)->old_push(vcc, skb);
1781da177e4SLinus Torvalds return 0;
1791da177e4SLinus Torvalds }
1801da177e4SLinus Torvalds
1811da177e4SLinus Torvalds static const unsigned char llc_oui[] = {
1821da177e4SLinus Torvalds 0xaa, /* DSAP: non-ISO */
1831da177e4SLinus Torvalds 0xaa, /* SSAP: non-ISO */
1841da177e4SLinus Torvalds 0x03, /* Ctrl: Unnumbered Information Command PDU */
1851da177e4SLinus Torvalds 0x00, /* OUI: EtherType */
1861da177e4SLinus Torvalds 0x00,
187e49e76dbSStephen Hemminger 0x00
188e49e76dbSStephen Hemminger };
1891da177e4SLinus Torvalds
clip_push(struct atm_vcc * vcc,struct sk_buff * skb)1901da177e4SLinus Torvalds static void clip_push(struct atm_vcc *vcc, struct sk_buff *skb)
1911da177e4SLinus Torvalds {
1921da177e4SLinus Torvalds struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
1931da177e4SLinus Torvalds
19499824461SJoe Perches pr_debug("\n");
1953b829366SJorge Boncompte [DTI2]
1963b829366SJorge Boncompte [DTI2] if (!clip_devs) {
1973b829366SJorge Boncompte [DTI2] atm_return(vcc, skb->truesize);
1983b829366SJorge Boncompte [DTI2] kfree_skb(skb);
1993b829366SJorge Boncompte [DTI2] return;
2003b829366SJorge Boncompte [DTI2] }
2013b829366SJorge Boncompte [DTI2]
2021da177e4SLinus Torvalds if (!skb) {
20352240062SStephen Hemminger pr_debug("removing VCC %p\n", clip_vcc);
204e49e76dbSStephen Hemminger if (clip_vcc->entry)
205e49e76dbSStephen Hemminger unlink_clip_vcc(clip_vcc);
2061da177e4SLinus Torvalds clip_vcc->old_push(vcc, NULL); /* pass on the bad news */
2071da177e4SLinus Torvalds kfree(clip_vcc);
2081da177e4SLinus Torvalds return;
2091da177e4SLinus Torvalds }
2101da177e4SLinus Torvalds atm_return(vcc, skb->truesize);
2111da177e4SLinus Torvalds skb->dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : clip_devs;
2121da177e4SLinus Torvalds /* clip_vcc->entry == NULL if we don't have an IP address yet */
2131da177e4SLinus Torvalds if (!skb->dev) {
2141da177e4SLinus Torvalds dev_kfree_skb_any(skb);
2151da177e4SLinus Torvalds return;
2161da177e4SLinus Torvalds }
2171da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc;
218459a98edSArnaldo Carvalho de Melo skb_reset_mac_header(skb);
219e956ea1bSJoe Perches if (!clip_vcc->encap ||
220e956ea1bSJoe Perches skb->len < RFC1483LLC_LEN ||
221e956ea1bSJoe Perches memcmp(skb->data, llc_oui, sizeof(llc_oui)))
222e49e76dbSStephen Hemminger skb->protocol = htons(ETH_P_IP);
2231da177e4SLinus Torvalds else {
22430d492daSAl Viro skb->protocol = ((__be16 *)skb->data)[3];
2251da177e4SLinus Torvalds skb_pull(skb, RFC1483LLC_LEN);
2261da177e4SLinus Torvalds if (skb->protocol == htons(ETH_P_ARP)) {
2271a6afe8aSStephen Hemminger skb->dev->stats.rx_packets++;
2281a6afe8aSStephen Hemminger skb->dev->stats.rx_bytes += skb->len;
2291da177e4SLinus Torvalds clip_arp_rcv(skb);
2301da177e4SLinus Torvalds return;
2311da177e4SLinus Torvalds }
2321da177e4SLinus Torvalds }
2331da177e4SLinus Torvalds clip_vcc->last_use = jiffies;
2341a6afe8aSStephen Hemminger skb->dev->stats.rx_packets++;
2351a6afe8aSStephen Hemminger skb->dev->stats.rx_bytes += skb->len;
2361da177e4SLinus Torvalds memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
2371da177e4SLinus Torvalds netif_rx(skb);
2381da177e4SLinus Torvalds }
2391da177e4SLinus Torvalds
2401da177e4SLinus Torvalds /*
2411da177e4SLinus Torvalds * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that
2421da177e4SLinus Torvalds * clip_pop is atomic with respect to the critical section in clip_start_xmit.
2431da177e4SLinus Torvalds */
2441da177e4SLinus Torvalds
clip_pop(struct atm_vcc * vcc,struct sk_buff * skb)2451da177e4SLinus Torvalds static void clip_pop(struct atm_vcc *vcc, struct sk_buff *skb)
2461da177e4SLinus Torvalds {
2471da177e4SLinus Torvalds struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
2481da177e4SLinus Torvalds struct net_device *dev = skb->dev;
2491da177e4SLinus Torvalds int old;
2501da177e4SLinus Torvalds unsigned long flags;
2511da177e4SLinus Torvalds
25299824461SJoe Perches pr_debug("(vcc %p)\n", vcc);
2531da177e4SLinus Torvalds clip_vcc->old_pop(vcc, skb);
2541da177e4SLinus Torvalds /* skb->dev == NULL in outbound ARP packets */
255e49e76dbSStephen Hemminger if (!dev)
256e49e76dbSStephen Hemminger return;
2571da177e4SLinus Torvalds spin_lock_irqsave(&PRIV(dev)->xoff_lock, flags);
2581da177e4SLinus Torvalds if (atm_may_send(vcc, 0)) {
2591da177e4SLinus Torvalds old = xchg(&clip_vcc->xoff, 0);
260e49e76dbSStephen Hemminger if (old)
261e49e76dbSStephen Hemminger netif_wake_queue(dev);
2621da177e4SLinus Torvalds }
2631da177e4SLinus Torvalds spin_unlock_irqrestore(&PRIV(dev)->xoff_lock, flags);
2641da177e4SLinus Torvalds }
2651da177e4SLinus Torvalds
clip_neigh_solicit(struct neighbour * neigh,struct sk_buff * skb)2661da177e4SLinus Torvalds static void clip_neigh_solicit(struct neighbour *neigh, struct sk_buff *skb)
2671da177e4SLinus Torvalds {
268869759b9SDavid Miller __be32 *ip = (__be32 *) neigh->primary_key;
269869759b9SDavid Miller
27099824461SJoe Perches pr_debug("(neigh %p, skb %p)\n", neigh, skb);
271869759b9SDavid Miller to_atmarpd(act_need, PRIV(neigh->dev)->number, *ip);
2721da177e4SLinus Torvalds }
2731da177e4SLinus Torvalds
clip_neigh_error(struct neighbour * neigh,struct sk_buff * skb)2741da177e4SLinus Torvalds static void clip_neigh_error(struct neighbour *neigh, struct sk_buff *skb)
2751da177e4SLinus Torvalds {
2761da177e4SLinus Torvalds #ifndef CONFIG_ATM_CLIP_NO_ICMP
2771da177e4SLinus Torvalds icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
2781da177e4SLinus Torvalds #endif
2791da177e4SLinus Torvalds kfree_skb(skb);
2801da177e4SLinus Torvalds }
2811da177e4SLinus Torvalds
28289d69d2bSStephen Hemminger static const struct neigh_ops clip_neigh_ops = {
2831da177e4SLinus Torvalds .family = AF_INET,
2841da177e4SLinus Torvalds .solicit = clip_neigh_solicit,
2851da177e4SLinus Torvalds .error_report = clip_neigh_error,
2868f40b161SDavid S. Miller .output = neigh_direct_output,
2878f40b161SDavid S. Miller .connected_output = neigh_direct_output,
2881da177e4SLinus Torvalds };
2891da177e4SLinus Torvalds
clip_constructor(struct net_device * dev,struct neighbour * neigh)290503eebc2SJiri Pirko static int clip_constructor(struct net_device *dev, struct neighbour *neigh)
2911da177e4SLinus Torvalds {
292869759b9SDavid Miller struct atmarp_entry *entry = neighbour_priv(neigh);
2931da177e4SLinus Torvalds
29432092ecfSDavid Miller if (neigh->tbl->family != AF_INET)
29532092ecfSDavid Miller return -EINVAL;
29632092ecfSDavid Miller
297e49e76dbSStephen Hemminger if (neigh->type != RTN_UNICAST)
298e49e76dbSStephen Hemminger return -EINVAL;
2991da177e4SLinus Torvalds
30032092ecfSDavid Miller neigh->nud_state = NUD_NONE;
3011da177e4SLinus Torvalds neigh->ops = &clip_neigh_ops;
30232092ecfSDavid Miller neigh->output = neigh->ops->output;
3031da177e4SLinus Torvalds entry->neigh = neigh;
3041da177e4SLinus Torvalds entry->vccs = NULL;
3051da177e4SLinus Torvalds entry->expires = jiffies - 1;
30632092ecfSDavid Miller
3071da177e4SLinus Torvalds return 0;
3081da177e4SLinus Torvalds }
3091da177e4SLinus Torvalds
3101da177e4SLinus Torvalds /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
3111da177e4SLinus Torvalds
3121da177e4SLinus Torvalds /*
3131da177e4SLinus Torvalds * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
3141da177e4SLinus Torvalds * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
3151da177e4SLinus Torvalds * don't increment the usage count. This is used to create entries in
3161da177e4SLinus Torvalds * clip_setentry.
3171da177e4SLinus Torvalds */
3181da177e4SLinus Torvalds
clip_encap(struct atm_vcc * vcc,int mode)3191da177e4SLinus Torvalds static int clip_encap(struct atm_vcc *vcc, int mode)
3201da177e4SLinus Torvalds {
32134f5b006SSasha Levin if (!CLIP_VCC(vcc))
32234f5b006SSasha Levin return -EBADFD;
32334f5b006SSasha Levin
3241da177e4SLinus Torvalds CLIP_VCC(vcc)->encap = mode;
3251da177e4SLinus Torvalds return 0;
3261da177e4SLinus Torvalds }
3271da177e4SLinus Torvalds
clip_start_xmit(struct sk_buff * skb,struct net_device * dev)3283c805a22SStephen Hemminger static netdev_tx_t clip_start_xmit(struct sk_buff *skb,
3293c805a22SStephen Hemminger struct net_device *dev)
3301da177e4SLinus Torvalds {
3311da177e4SLinus Torvalds struct clip_priv *clip_priv = PRIV(dev);
33269cce1d1SDavid S. Miller struct dst_entry *dst = skb_dst(skb);
3331da177e4SLinus Torvalds struct atmarp_entry *entry;
33469cce1d1SDavid S. Miller struct neighbour *n;
3351da177e4SLinus Torvalds struct atm_vcc *vcc;
3367161c76fSDavid S. Miller struct rtable *rt;
3377161c76fSDavid S. Miller __be32 *daddr;
3381da177e4SLinus Torvalds int old;
3391da177e4SLinus Torvalds unsigned long flags;
3401da177e4SLinus Torvalds
34199824461SJoe Perches pr_debug("(skb %p)\n", skb);
34269cce1d1SDavid S. Miller if (!dst) {
34399824461SJoe Perches pr_err("skb_dst(skb) == NULL\n");
3441da177e4SLinus Torvalds dev_kfree_skb(skb);
3451a6afe8aSStephen Hemminger dev->stats.tx_dropped++;
3466ed10654SPatrick McHardy return NETDEV_TX_OK;
3471da177e4SLinus Torvalds }
3487161c76fSDavid S. Miller rt = (struct rtable *) dst;
3491550c171SDavid Ahern if (rt->rt_gw_family == AF_INET)
3501550c171SDavid Ahern daddr = &rt->rt_gw4;
3517161c76fSDavid S. Miller else
3527161c76fSDavid S. Miller daddr = &ip_hdr(skb)->daddr;
3537161c76fSDavid S. Miller n = dst_neigh_lookup(dst, daddr);
35469cce1d1SDavid S. Miller if (!n) {
35599824461SJoe Perches pr_err("NO NEIGHBOUR !\n");
3561da177e4SLinus Torvalds dev_kfree_skb(skb);
3571a6afe8aSStephen Hemminger dev->stats.tx_dropped++;
3586ed10654SPatrick McHardy return NETDEV_TX_OK;
3591da177e4SLinus Torvalds }
360869759b9SDavid Miller entry = neighbour_priv(n);
3611da177e4SLinus Torvalds if (!entry->vccs) {
3621da177e4SLinus Torvalds if (time_after(jiffies, entry->expires)) {
3631da177e4SLinus Torvalds /* should be resolved */
3641da177e4SLinus Torvalds entry->expires = jiffies + ATMARP_RETRY_DELAY * HZ;
365869759b9SDavid Miller to_atmarpd(act_need, PRIV(dev)->number, *((__be32 *)n->primary_key));
3661da177e4SLinus Torvalds }
3671da177e4SLinus Torvalds if (entry->neigh->arp_queue.qlen < ATMARP_MAX_UNRES_PACKETS)
3681da177e4SLinus Torvalds skb_queue_tail(&entry->neigh->arp_queue, skb);
3691da177e4SLinus Torvalds else {
3701da177e4SLinus Torvalds dev_kfree_skb(skb);
3711a6afe8aSStephen Hemminger dev->stats.tx_dropped++;
3721da177e4SLinus Torvalds }
3737161c76fSDavid S. Miller goto out_release_neigh;
3741da177e4SLinus Torvalds }
37552240062SStephen Hemminger pr_debug("neigh %p, vccs %p\n", entry, entry->vccs);
3761da177e4SLinus Torvalds ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc;
37769cce1d1SDavid S. Miller pr_debug("using neighbour %p, vcc %p\n", n, vcc);
3781da177e4SLinus Torvalds if (entry->vccs->encap) {
3791da177e4SLinus Torvalds void *here;
3801da177e4SLinus Torvalds
3811da177e4SLinus Torvalds here = skb_push(skb, RFC1483LLC_LEN);
3821da177e4SLinus Torvalds memcpy(here, llc_oui, sizeof(llc_oui));
38330d492daSAl Viro ((__be16 *) here)[3] = skb->protocol;
3841da177e4SLinus Torvalds }
3859bbe60a6SDavid Woodhouse atm_account_tx(vcc, skb);
3861da177e4SLinus Torvalds entry->vccs->last_use = jiffies;
38752240062SStephen Hemminger pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->dev);
3881da177e4SLinus Torvalds old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */
3891da177e4SLinus Torvalds if (old) {
390ef423a41SJoe Perches pr_warn("XOFF->XOFF transition\n");
3917161c76fSDavid S. Miller goto out_release_neigh;
3921da177e4SLinus Torvalds }
3931a6afe8aSStephen Hemminger dev->stats.tx_packets++;
3941a6afe8aSStephen Hemminger dev->stats.tx_bytes += skb->len;
3955ff765f3SStephen Hemminger vcc->send(vcc, skb);
3961da177e4SLinus Torvalds if (atm_may_send(vcc, 0)) {
3971da177e4SLinus Torvalds entry->vccs->xoff = 0;
3987161c76fSDavid S. Miller goto out_release_neigh;
3991da177e4SLinus Torvalds }
4001da177e4SLinus Torvalds spin_lock_irqsave(&clip_priv->xoff_lock, flags);
4011da177e4SLinus Torvalds netif_stop_queue(dev); /* XOFF -> throttle immediately */
4021da177e4SLinus Torvalds barrier();
4031da177e4SLinus Torvalds if (!entry->vccs->xoff)
4041da177e4SLinus Torvalds netif_start_queue(dev);
4051da177e4SLinus Torvalds /* Oh, we just raced with clip_pop. netif_start_queue should be
4061da177e4SLinus Torvalds good enough, because nothing should really be asleep because
4071da177e4SLinus Torvalds of the brief netif_stop_queue. If this isn't true or if it
4081da177e4SLinus Torvalds changes, use netif_wake_queue instead. */
4091da177e4SLinus Torvalds spin_unlock_irqrestore(&clip_priv->xoff_lock, flags);
4107161c76fSDavid S. Miller out_release_neigh:
4117161c76fSDavid S. Miller neigh_release(n);
4126ed10654SPatrick McHardy return NETDEV_TX_OK;
4131da177e4SLinus Torvalds }
4141da177e4SLinus Torvalds
clip_mkip(struct atm_vcc * vcc,int timeout)4151da177e4SLinus Torvalds static int clip_mkip(struct atm_vcc *vcc, int timeout)
4161da177e4SLinus Torvalds {
4171da177e4SLinus Torvalds struct clip_vcc *clip_vcc;
4181da177e4SLinus Torvalds
419e49e76dbSStephen Hemminger if (!vcc->push)
420e49e76dbSStephen Hemminger return -EBADFD;
4211da177e4SLinus Torvalds clip_vcc = kmalloc(sizeof(struct clip_vcc), GFP_KERNEL);
422e49e76dbSStephen Hemminger if (!clip_vcc)
423e49e76dbSStephen Hemminger return -ENOMEM;
42499824461SJoe Perches pr_debug("%p vcc %p\n", clip_vcc, vcc);
4251da177e4SLinus Torvalds clip_vcc->vcc = vcc;
4261da177e4SLinus Torvalds vcc->user_back = clip_vcc;
4271da177e4SLinus Torvalds set_bit(ATM_VF_IS_CLIP, &vcc->flags);
4281da177e4SLinus Torvalds clip_vcc->entry = NULL;
4291da177e4SLinus Torvalds clip_vcc->xoff = 0;
4301da177e4SLinus Torvalds clip_vcc->encap = 1;
4311da177e4SLinus Torvalds clip_vcc->last_use = jiffies;
4321da177e4SLinus Torvalds clip_vcc->idle_timeout = timeout * HZ;
4331da177e4SLinus Torvalds clip_vcc->old_push = vcc->push;
4341da177e4SLinus Torvalds clip_vcc->old_pop = vcc->pop;
4351da177e4SLinus Torvalds vcc->push = clip_push;
4361da177e4SLinus Torvalds vcc->pop = clip_pop;
437c40a27f4SDavid S. Miller
4381da177e4SLinus Torvalds /* re-process everything received between connection setup and MKIP */
4394e55f578SJorge Boncompte [DTI2] vcc_process_recv_queue(vcc);
4403b829366SJorge Boncompte [DTI2]
4411da177e4SLinus Torvalds return 0;
4421da177e4SLinus Torvalds }
4431da177e4SLinus Torvalds
clip_setentry(struct atm_vcc * vcc,__be32 ip)44430d492daSAl Viro static int clip_setentry(struct atm_vcc *vcc, __be32 ip)
4451da177e4SLinus Torvalds {
4461da177e4SLinus Torvalds struct neighbour *neigh;
4471da177e4SLinus Torvalds struct atmarp_entry *entry;
4481da177e4SLinus Torvalds int error;
4491da177e4SLinus Torvalds struct clip_vcc *clip_vcc;
4501da177e4SLinus Torvalds struct rtable *rt;
4511da177e4SLinus Torvalds
4521da177e4SLinus Torvalds if (vcc->push != clip_push) {
453ef423a41SJoe Perches pr_warn("non-CLIP VCC\n");
4541da177e4SLinus Torvalds return -EBADF;
4551da177e4SLinus Torvalds }
4561da177e4SLinus Torvalds clip_vcc = CLIP_VCC(vcc);
4571da177e4SLinus Torvalds if (!ip) {
4581da177e4SLinus Torvalds if (!clip_vcc->entry) {
45999824461SJoe Perches pr_err("hiding hidden ATMARP entry\n");
4601da177e4SLinus Torvalds return 0;
4611da177e4SLinus Torvalds }
46299824461SJoe Perches pr_debug("remove\n");
4631da177e4SLinus Torvalds unlink_clip_vcc(clip_vcc);
4641da177e4SLinus Torvalds return 0;
4651da177e4SLinus Torvalds }
46678fbfd8aSDavid S. Miller rt = ip_route_output(&init_net, ip, 0, 1, 0);
467b23dd4feSDavid S. Miller if (IS_ERR(rt))
468b23dd4feSDavid S. Miller return PTR_ERR(rt);
46932092ecfSDavid Miller neigh = __neigh_lookup(&arp_tbl, &ip, rt->dst.dev, 1);
4701da177e4SLinus Torvalds ip_rt_put(rt);
4711da177e4SLinus Torvalds if (!neigh)
4721da177e4SLinus Torvalds return -ENOMEM;
473869759b9SDavid Miller entry = neighbour_priv(neigh);
4741da177e4SLinus Torvalds if (entry != clip_vcc->entry) {
475e49e76dbSStephen Hemminger if (!clip_vcc->entry)
47699824461SJoe Perches pr_debug("add\n");
4771da177e4SLinus Torvalds else {
47899824461SJoe Perches pr_debug("update\n");
4791da177e4SLinus Torvalds unlink_clip_vcc(clip_vcc);
4801da177e4SLinus Torvalds }
4811da177e4SLinus Torvalds link_vcc(clip_vcc, entry);
4821da177e4SLinus Torvalds }
4831da177e4SLinus Torvalds error = neigh_update(neigh, llc_oui, NUD_PERMANENT,
4847b8f7a40SRoopa Prabhu NEIGH_UPDATE_F_OVERRIDE | NEIGH_UPDATE_F_ADMIN, 0);
4851da177e4SLinus Torvalds neigh_release(neigh);
4861da177e4SLinus Torvalds return error;
4871da177e4SLinus Torvalds }
4881da177e4SLinus Torvalds
489dde09758SStephen Hemminger static const struct net_device_ops clip_netdev_ops = {
490dde09758SStephen Hemminger .ndo_start_xmit = clip_start_xmit,
49132092ecfSDavid Miller .ndo_neigh_construct = clip_constructor,
492dde09758SStephen Hemminger };
493dde09758SStephen Hemminger
clip_setup(struct net_device * dev)4941da177e4SLinus Torvalds static void clip_setup(struct net_device *dev)
4951da177e4SLinus Torvalds {
496dde09758SStephen Hemminger dev->netdev_ops = &clip_netdev_ops;
4971da177e4SLinus Torvalds dev->type = ARPHRD_ATM;
498596b9b68SDavid Miller dev->neigh_priv_len = sizeof(struct atmarp_entry);
4991da177e4SLinus Torvalds dev->hard_header_len = RFC1483LLC_LEN;
5001da177e4SLinus Torvalds dev->mtu = RFC1626_MTU;
5011da177e4SLinus Torvalds dev->tx_queue_len = 100; /* "normal" queue (packets) */
5021da177e4SLinus Torvalds /* When using a "real" qdisc, the qdisc determines the queue */
5031da177e4SLinus Torvalds /* length. tx_queue_len is only used for the default case, */
5041da177e4SLinus Torvalds /* without any more elaborate queuing. 100 is a reasonable */
5051da177e4SLinus Torvalds /* compromise between decent burst-tolerance and protection */
5061da177e4SLinus Torvalds /* against memory hogs. */
50702875878SEric Dumazet netif_keep_dst(dev);
5081da177e4SLinus Torvalds }
5091da177e4SLinus Torvalds
clip_create(int number)5101da177e4SLinus Torvalds static int clip_create(int number)
5111da177e4SLinus Torvalds {
5121da177e4SLinus Torvalds struct net_device *dev;
5131da177e4SLinus Torvalds struct clip_priv *clip_priv;
5141da177e4SLinus Torvalds int error;
5151da177e4SLinus Torvalds
5161da177e4SLinus Torvalds if (number != -1) {
5171da177e4SLinus Torvalds for (dev = clip_devs; dev; dev = PRIV(dev)->next)
518e49e76dbSStephen Hemminger if (PRIV(dev)->number == number)
519e49e76dbSStephen Hemminger return -EEXIST;
520e49e76dbSStephen Hemminger } else {
5211da177e4SLinus Torvalds number = 0;
5221da177e4SLinus Torvalds for (dev = clip_devs; dev; dev = PRIV(dev)->next)
5231da177e4SLinus Torvalds if (PRIV(dev)->number >= number)
5241da177e4SLinus Torvalds number = PRIV(dev)->number + 1;
5251da177e4SLinus Torvalds }
526c835a677STom Gundersen dev = alloc_netdev(sizeof(struct clip_priv), "", NET_NAME_UNKNOWN,
527c835a677STom Gundersen clip_setup);
5281da177e4SLinus Torvalds if (!dev)
5291da177e4SLinus Torvalds return -ENOMEM;
5301da177e4SLinus Torvalds clip_priv = PRIV(dev);
5311da177e4SLinus Torvalds sprintf(dev->name, "atm%d", number);
5321da177e4SLinus Torvalds spin_lock_init(&clip_priv->xoff_lock);
5331da177e4SLinus Torvalds clip_priv->number = number;
5341da177e4SLinus Torvalds error = register_netdev(dev);
5351da177e4SLinus Torvalds if (error) {
5361da177e4SLinus Torvalds free_netdev(dev);
5371da177e4SLinus Torvalds return error;
5381da177e4SLinus Torvalds }
5391da177e4SLinus Torvalds clip_priv->next = clip_devs;
5401da177e4SLinus Torvalds clip_devs = dev;
54152240062SStephen Hemminger pr_debug("registered (net:%s)\n", dev->name);
5421da177e4SLinus Torvalds return number;
5431da177e4SLinus Torvalds }
5441da177e4SLinus Torvalds
clip_device_event(struct notifier_block * this,unsigned long event,void * ptr)5451da177e4SLinus Torvalds static int clip_device_event(struct notifier_block *this, unsigned long event,
546351638e7SJiri Pirko void *ptr)
5471da177e4SLinus Torvalds {
548351638e7SJiri Pirko struct net_device *dev = netdev_notifier_info_to_dev(ptr);
549f3a0592bSStephen Hemminger
550721499e8SYOSHIFUJI Hideaki if (!net_eq(dev_net(dev), &init_net))
551e9dc8653SEric W. Biederman return NOTIFY_DONE;
552e9dc8653SEric W. Biederman
55332092ecfSDavid Miller if (event == NETDEV_UNREGISTER)
5541da177e4SLinus Torvalds return NOTIFY_DONE;
555f3a0592bSStephen Hemminger
556f3a0592bSStephen Hemminger /* ignore non-CLIP devices */
557dde09758SStephen Hemminger if (dev->type != ARPHRD_ATM || dev->netdev_ops != &clip_netdev_ops)
558f3a0592bSStephen Hemminger return NOTIFY_DONE;
559f3a0592bSStephen Hemminger
5601da177e4SLinus Torvalds switch (event) {
5611da177e4SLinus Torvalds case NETDEV_UP:
56299824461SJoe Perches pr_debug("NETDEV_UP\n");
5635ff765f3SStephen Hemminger to_atmarpd(act_up, PRIV(dev)->number, 0);
5641da177e4SLinus Torvalds break;
5651da177e4SLinus Torvalds case NETDEV_GOING_DOWN:
56699824461SJoe Perches pr_debug("NETDEV_DOWN\n");
5675ff765f3SStephen Hemminger to_atmarpd(act_down, PRIV(dev)->number, 0);
5681da177e4SLinus Torvalds break;
5691da177e4SLinus Torvalds case NETDEV_CHANGE:
5701da177e4SLinus Torvalds case NETDEV_CHANGEMTU:
57199824461SJoe Perches pr_debug("NETDEV_CHANGE*\n");
5725ff765f3SStephen Hemminger to_atmarpd(act_change, PRIV(dev)->number, 0);
5731da177e4SLinus Torvalds break;
5741da177e4SLinus Torvalds }
5751da177e4SLinus Torvalds return NOTIFY_DONE;
5761da177e4SLinus Torvalds }
5771da177e4SLinus Torvalds
clip_inet_event(struct notifier_block * this,unsigned long event,void * ifa)5781da177e4SLinus Torvalds static int clip_inet_event(struct notifier_block *this, unsigned long event,
5791da177e4SLinus Torvalds void *ifa)
5801da177e4SLinus Torvalds {
5811da177e4SLinus Torvalds struct in_device *in_dev;
58275538c2bSCong Wang struct netdev_notifier_info info;
5831da177e4SLinus Torvalds
5841da177e4SLinus Torvalds in_dev = ((struct in_ifaddr *)ifa)->ifa_dev;
5851da177e4SLinus Torvalds /*
5861da177e4SLinus Torvalds * Transitions are of the down-change-up type, so it's sufficient to
5871da177e4SLinus Torvalds * handle the change on up.
5881da177e4SLinus Torvalds */
589e49e76dbSStephen Hemminger if (event != NETDEV_UP)
590e49e76dbSStephen Hemminger return NOTIFY_DONE;
59175538c2bSCong Wang netdev_notifier_info_init(&info, in_dev->dev);
59275538c2bSCong Wang return clip_device_event(this, NETDEV_CHANGE, &info);
5931da177e4SLinus Torvalds }
5941da177e4SLinus Torvalds
5951da177e4SLinus Torvalds static struct notifier_block clip_dev_notifier = {
5965ff765f3SStephen Hemminger .notifier_call = clip_device_event,
5971da177e4SLinus Torvalds };
5981da177e4SLinus Torvalds
5991da177e4SLinus Torvalds
6001da177e4SLinus Torvalds
6011da177e4SLinus Torvalds static struct notifier_block clip_inet_notifier = {
6025ff765f3SStephen Hemminger .notifier_call = clip_inet_event,
6031da177e4SLinus Torvalds };
6041da177e4SLinus Torvalds
6051da177e4SLinus Torvalds
6061da177e4SLinus Torvalds
atmarpd_close(struct atm_vcc * vcc)6071da177e4SLinus Torvalds static void atmarpd_close(struct atm_vcc *vcc)
6081da177e4SLinus Torvalds {
60999824461SJoe Perches pr_debug("\n");
610f3a0592bSStephen Hemminger
611f3a0592bSStephen Hemminger rtnl_lock();
612f3a0592bSStephen Hemminger atmarpd = NULL;
6131da177e4SLinus Torvalds skb_queue_purge(&sk_atm(vcc)->sk_receive_queue);
614f3a0592bSStephen Hemminger rtnl_unlock();
615f3a0592bSStephen Hemminger
61652240062SStephen Hemminger pr_debug("(done)\n");
6171da177e4SLinus Torvalds module_put(THIS_MODULE);
6181da177e4SLinus Torvalds }
6191da177e4SLinus Torvalds
620800bb47eSBhumika Goyal static const struct atmdev_ops atmarpd_dev_ops = {
6211da177e4SLinus Torvalds .close = atmarpd_close
6221da177e4SLinus Torvalds };
6231da177e4SLinus Torvalds
6241da177e4SLinus Torvalds
6251da177e4SLinus Torvalds static struct atm_dev atmarpd_dev = {
6261da177e4SLinus Torvalds .ops = &atmarpd_dev_ops,
6271da177e4SLinus Torvalds .type = "arpd",
6281da177e4SLinus Torvalds .number = 999,
6294ef8d0aeSMilind Arun Choudhary .lock = __SPIN_LOCK_UNLOCKED(atmarpd_dev.lock)
6301da177e4SLinus Torvalds };
6311da177e4SLinus Torvalds
6321da177e4SLinus Torvalds
atm_init_atmarp(struct atm_vcc * vcc)6331da177e4SLinus Torvalds static int atm_init_atmarp(struct atm_vcc *vcc)
6341da177e4SLinus Torvalds {
635f3a0592bSStephen Hemminger rtnl_lock();
636f3a0592bSStephen Hemminger if (atmarpd) {
637f3a0592bSStephen Hemminger rtnl_unlock();
638f3a0592bSStephen Hemminger return -EADDRINUSE;
639f3a0592bSStephen Hemminger }
640f3a0592bSStephen Hemminger
6412d907392SStephen Hemminger mod_timer(&idle_timer, jiffies + CLIP_CHECK_INTERVAL * HZ);
6422d907392SStephen Hemminger
6431da177e4SLinus Torvalds atmarpd = vcc;
6441da177e4SLinus Torvalds set_bit(ATM_VF_META, &vcc->flags);
6451da177e4SLinus Torvalds set_bit(ATM_VF_READY, &vcc->flags);
6461da177e4SLinus Torvalds /* allow replies and avoid getting closed if signaling dies */
6471da177e4SLinus Torvalds vcc->dev = &atmarpd_dev;
6481da177e4SLinus Torvalds vcc_insert_socket(sk_atm(vcc));
6491da177e4SLinus Torvalds vcc->push = NULL;
6501da177e4SLinus Torvalds vcc->pop = NULL; /* crash */
6511da177e4SLinus Torvalds vcc->push_oam = NULL; /* crash */
652f3a0592bSStephen Hemminger rtnl_unlock();
6531da177e4SLinus Torvalds return 0;
6541da177e4SLinus Torvalds }
6551da177e4SLinus Torvalds
clip_ioctl(struct socket * sock,unsigned int cmd,unsigned long arg)6561da177e4SLinus Torvalds static int clip_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
6571da177e4SLinus Torvalds {
6581da177e4SLinus Torvalds struct atm_vcc *vcc = ATM_SD(sock);
6591da177e4SLinus Torvalds int err = 0;
6601da177e4SLinus Torvalds
6611da177e4SLinus Torvalds switch (cmd) {
6621da177e4SLinus Torvalds case SIOCMKCLIP:
6631da177e4SLinus Torvalds case ATMARPD_CTRL:
6641da177e4SLinus Torvalds case ATMARP_MKIP:
6651da177e4SLinus Torvalds case ATMARP_SETENTRY:
6661da177e4SLinus Torvalds case ATMARP_ENCAP:
6671da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN))
6681da177e4SLinus Torvalds return -EPERM;
6691da177e4SLinus Torvalds break;
6701da177e4SLinus Torvalds default:
6711da177e4SLinus Torvalds return -ENOIOCTLCMD;
6721da177e4SLinus Torvalds }
6731da177e4SLinus Torvalds
6741da177e4SLinus Torvalds switch (cmd) {
6751da177e4SLinus Torvalds case SIOCMKCLIP:
6761da177e4SLinus Torvalds err = clip_create(arg);
6771da177e4SLinus Torvalds break;
6781da177e4SLinus Torvalds case ATMARPD_CTRL:
6791da177e4SLinus Torvalds err = atm_init_atmarp(vcc);
6801da177e4SLinus Torvalds if (!err) {
6811da177e4SLinus Torvalds sock->state = SS_CONNECTED;
6821da177e4SLinus Torvalds __module_get(THIS_MODULE);
6831da177e4SLinus Torvalds }
6841da177e4SLinus Torvalds break;
6851da177e4SLinus Torvalds case ATMARP_MKIP:
6861da177e4SLinus Torvalds err = clip_mkip(vcc, arg);
6871da177e4SLinus Torvalds break;
6881da177e4SLinus Torvalds case ATMARP_SETENTRY:
68930d492daSAl Viro err = clip_setentry(vcc, (__force __be32)arg);
6901da177e4SLinus Torvalds break;
6911da177e4SLinus Torvalds case ATMARP_ENCAP:
6921da177e4SLinus Torvalds err = clip_encap(vcc, arg);
6931da177e4SLinus Torvalds break;
6941da177e4SLinus Torvalds }
6951da177e4SLinus Torvalds return err;
6961da177e4SLinus Torvalds }
6971da177e4SLinus Torvalds
6981da177e4SLinus Torvalds static struct atm_ioctl clip_ioctl_ops = {
6991da177e4SLinus Torvalds .owner = THIS_MODULE,
7001da177e4SLinus Torvalds .ioctl = clip_ioctl,
7011da177e4SLinus Torvalds };
7021da177e4SLinus Torvalds
7031da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
7041da177e4SLinus Torvalds
svc_addr(struct seq_file * seq,struct sockaddr_atmsvc * addr)7051da177e4SLinus Torvalds static void svc_addr(struct seq_file *seq, struct sockaddr_atmsvc *addr)
7061da177e4SLinus Torvalds {
7071da177e4SLinus Torvalds static int code[] = { 1, 2, 10, 6, 1, 0 };
7081da177e4SLinus Torvalds static int e164[] = { 1, 8, 4, 6, 1, 0 };
7091da177e4SLinus Torvalds
7101da177e4SLinus Torvalds if (*addr->sas_addr.pub) {
7111da177e4SLinus Torvalds seq_printf(seq, "%s", addr->sas_addr.pub);
7121da177e4SLinus Torvalds if (*addr->sas_addr.prv)
7131da177e4SLinus Torvalds seq_putc(seq, '+');
7141da177e4SLinus Torvalds } else if (!*addr->sas_addr.prv) {
7151da177e4SLinus Torvalds seq_printf(seq, "%s", "(none)");
7161da177e4SLinus Torvalds return;
7171da177e4SLinus Torvalds }
7181da177e4SLinus Torvalds if (*addr->sas_addr.prv) {
7191da177e4SLinus Torvalds unsigned char *prv = addr->sas_addr.prv;
7201da177e4SLinus Torvalds int *fields;
7211da177e4SLinus Torvalds int i, j;
7221da177e4SLinus Torvalds
7231da177e4SLinus Torvalds fields = *prv == ATM_AFI_E164 ? e164 : code;
7241da177e4SLinus Torvalds for (i = 0; fields[i]; i++) {
7251da177e4SLinus Torvalds for (j = fields[i]; j; j--)
7261da177e4SLinus Torvalds seq_printf(seq, "%02X", *prv++);
7271da177e4SLinus Torvalds if (fields[i + 1])
7281da177e4SLinus Torvalds seq_putc(seq, '.');
7291da177e4SLinus Torvalds }
7301da177e4SLinus Torvalds }
7311da177e4SLinus Torvalds }
7321da177e4SLinus Torvalds
7331da177e4SLinus Torvalds /* This means the neighbour entry has no attached VCC objects. */
7341da177e4SLinus Torvalds #define SEQ_NO_VCC_TOKEN ((void *) 2)
7351da177e4SLinus Torvalds
atmarp_info(struct seq_file * seq,struct neighbour * n,struct atmarp_entry * entry,struct clip_vcc * clip_vcc)736869759b9SDavid Miller static void atmarp_info(struct seq_file *seq, struct neighbour *n,
7371da177e4SLinus Torvalds struct atmarp_entry *entry, struct clip_vcc *clip_vcc)
7381da177e4SLinus Torvalds {
739869759b9SDavid Miller struct net_device *dev = n->dev;
7401da177e4SLinus Torvalds unsigned long exp;
7411da177e4SLinus Torvalds char buf[17];
7421da177e4SLinus Torvalds int svc, llc, off;
7431da177e4SLinus Torvalds
7441da177e4SLinus Torvalds svc = ((clip_vcc == SEQ_NO_VCC_TOKEN) ||
7451da177e4SLinus Torvalds (sk_atm(clip_vcc->vcc)->sk_family == AF_ATMSVC));
7461da177e4SLinus Torvalds
747e49e76dbSStephen Hemminger llc = ((clip_vcc == SEQ_NO_VCC_TOKEN) || clip_vcc->encap);
7481da177e4SLinus Torvalds
7491da177e4SLinus Torvalds if (clip_vcc == SEQ_NO_VCC_TOKEN)
7501da177e4SLinus Torvalds exp = entry->neigh->used;
7511da177e4SLinus Torvalds else
7521da177e4SLinus Torvalds exp = clip_vcc->last_use;
7531da177e4SLinus Torvalds
7541da177e4SLinus Torvalds exp = (jiffies - exp) / HZ;
7551da177e4SLinus Torvalds
7561da177e4SLinus Torvalds seq_printf(seq, "%-6s%-4s%-4s%5ld ",
757e49e76dbSStephen Hemminger dev->name, svc ? "SVC" : "PVC", llc ? "LLC" : "NULL", exp);
7581da177e4SLinus Torvalds
759869759b9SDavid Miller off = scnprintf(buf, sizeof(buf) - 1, "%pI4", n->primary_key);
7601da177e4SLinus Torvalds while (off < 16)
7611da177e4SLinus Torvalds buf[off++] = ' ';
7621da177e4SLinus Torvalds buf[off] = '\0';
7631da177e4SLinus Torvalds seq_printf(seq, "%s", buf);
7641da177e4SLinus Torvalds
7651da177e4SLinus Torvalds if (clip_vcc == SEQ_NO_VCC_TOKEN) {
7661da177e4SLinus Torvalds if (time_before(jiffies, entry->expires))
7671da177e4SLinus Torvalds seq_printf(seq, "(resolving)\n");
7681da177e4SLinus Torvalds else
7691da177e4SLinus Torvalds seq_printf(seq, "(expired, ref %d)\n",
7709f237430SReshetova, Elena refcount_read(&entry->neigh->refcnt));
7711da177e4SLinus Torvalds } else if (!svc) {
7721da177e4SLinus Torvalds seq_printf(seq, "%d.%d.%d\n",
7731da177e4SLinus Torvalds clip_vcc->vcc->dev->number,
774e49e76dbSStephen Hemminger clip_vcc->vcc->vpi, clip_vcc->vcc->vci);
7751da177e4SLinus Torvalds } else {
7761da177e4SLinus Torvalds svc_addr(seq, &clip_vcc->vcc->remote);
7771da177e4SLinus Torvalds seq_putc(seq, '\n');
7781da177e4SLinus Torvalds }
7791da177e4SLinus Torvalds }
7801da177e4SLinus Torvalds
7811da177e4SLinus Torvalds struct clip_seq_state {
7821da177e4SLinus Torvalds /* This member must be first. */
7831da177e4SLinus Torvalds struct neigh_seq_state ns;
7841da177e4SLinus Torvalds
7851da177e4SLinus Torvalds /* Local to clip specific iteration. */
7861da177e4SLinus Torvalds struct clip_vcc *vcc;
7871da177e4SLinus Torvalds };
7881da177e4SLinus Torvalds
clip_seq_next_vcc(struct atmarp_entry * e,struct clip_vcc * curr)7891da177e4SLinus Torvalds static struct clip_vcc *clip_seq_next_vcc(struct atmarp_entry *e,
7901da177e4SLinus Torvalds struct clip_vcc *curr)
7911da177e4SLinus Torvalds {
7921da177e4SLinus Torvalds if (!curr) {
7931da177e4SLinus Torvalds curr = e->vccs;
7941da177e4SLinus Torvalds if (!curr)
7951da177e4SLinus Torvalds return SEQ_NO_VCC_TOKEN;
7961da177e4SLinus Torvalds return curr;
7971da177e4SLinus Torvalds }
7981da177e4SLinus Torvalds if (curr == SEQ_NO_VCC_TOKEN)
7991da177e4SLinus Torvalds return NULL;
8001da177e4SLinus Torvalds
8011da177e4SLinus Torvalds curr = curr->next;
8021da177e4SLinus Torvalds
8031da177e4SLinus Torvalds return curr;
8041da177e4SLinus Torvalds }
8051da177e4SLinus Torvalds
clip_seq_vcc_walk(struct clip_seq_state * state,struct atmarp_entry * e,loff_t * pos)8061da177e4SLinus Torvalds static void *clip_seq_vcc_walk(struct clip_seq_state *state,
8071da177e4SLinus Torvalds struct atmarp_entry *e, loff_t * pos)
8081da177e4SLinus Torvalds {
8091da177e4SLinus Torvalds struct clip_vcc *vcc = state->vcc;
8101da177e4SLinus Torvalds
8111da177e4SLinus Torvalds vcc = clip_seq_next_vcc(e, vcc);
8121da177e4SLinus Torvalds if (vcc && pos != NULL) {
8131da177e4SLinus Torvalds while (*pos) {
8141da177e4SLinus Torvalds vcc = clip_seq_next_vcc(e, vcc);
8151da177e4SLinus Torvalds if (!vcc)
8161da177e4SLinus Torvalds break;
8171da177e4SLinus Torvalds --(*pos);
8181da177e4SLinus Torvalds }
8191da177e4SLinus Torvalds }
8201da177e4SLinus Torvalds state->vcc = vcc;
8211da177e4SLinus Torvalds
8221da177e4SLinus Torvalds return vcc;
8231da177e4SLinus Torvalds }
8241da177e4SLinus Torvalds
clip_seq_sub_iter(struct neigh_seq_state * _state,struct neighbour * n,loff_t * pos)8251da177e4SLinus Torvalds static void *clip_seq_sub_iter(struct neigh_seq_state *_state,
8261da177e4SLinus Torvalds struct neighbour *n, loff_t * pos)
8271da177e4SLinus Torvalds {
8281da177e4SLinus Torvalds struct clip_seq_state *state = (struct clip_seq_state *)_state;
8291da177e4SLinus Torvalds
83032092ecfSDavid Miller if (n->dev->type != ARPHRD_ATM)
83132092ecfSDavid Miller return NULL;
83232092ecfSDavid Miller
833869759b9SDavid Miller return clip_seq_vcc_walk(state, neighbour_priv(n), pos);
8341da177e4SLinus Torvalds }
8351da177e4SLinus Torvalds
clip_seq_start(struct seq_file * seq,loff_t * pos)8361da177e4SLinus Torvalds static void *clip_seq_start(struct seq_file *seq, loff_t * pos)
8371da177e4SLinus Torvalds {
838ae22120aSDenis V. Lunev struct clip_seq_state *state = seq->private;
839ae22120aSDenis V. Lunev state->ns.neigh_sub_iter = clip_seq_sub_iter;
84032092ecfSDavid Miller return neigh_seq_start(seq, pos, &arp_tbl, NEIGH_SEQ_NEIGH_ONLY);
8411da177e4SLinus Torvalds }
8421da177e4SLinus Torvalds
clip_seq_show(struct seq_file * seq,void * v)8431da177e4SLinus Torvalds static int clip_seq_show(struct seq_file *seq, void *v)
8441da177e4SLinus Torvalds {
8451da177e4SLinus Torvalds static char atm_arp_banner[] =
8461da177e4SLinus Torvalds "IPitf TypeEncp Idle IP address ATM address\n";
8471da177e4SLinus Torvalds
8481da177e4SLinus Torvalds if (v == SEQ_START_TOKEN) {
8491da177e4SLinus Torvalds seq_puts(seq, atm_arp_banner);
8501da177e4SLinus Torvalds } else {
8511da177e4SLinus Torvalds struct clip_seq_state *state = seq->private;
8521da177e4SLinus Torvalds struct clip_vcc *vcc = state->vcc;
853869759b9SDavid Miller struct neighbour *n = v;
8541da177e4SLinus Torvalds
855869759b9SDavid Miller atmarp_info(seq, n, neighbour_priv(n), vcc);
8561da177e4SLinus Torvalds }
8571da177e4SLinus Torvalds return 0;
8581da177e4SLinus Torvalds }
8591da177e4SLinus Torvalds
86056b3d975SPhilippe De Muyter static const struct seq_operations arp_seq_ops = {
8611da177e4SLinus Torvalds .start = clip_seq_start,
8621da177e4SLinus Torvalds .next = neigh_seq_next,
8631da177e4SLinus Torvalds .stop = neigh_seq_stop,
8641da177e4SLinus Torvalds .show = clip_seq_show,
8651da177e4SLinus Torvalds };
8661da177e4SLinus Torvalds #endif
8671da177e4SLinus Torvalds
868dbee0d3fSWang Chen static void atm_clip_exit_noproc(void);
869dbee0d3fSWang Chen
atm_clip_init(void)8701da177e4SLinus Torvalds static int __init atm_clip_init(void)
8711da177e4SLinus Torvalds {
8721da177e4SLinus Torvalds register_atm_ioctl(&clip_ioctl_ops);
873f3a0592bSStephen Hemminger register_netdevice_notifier(&clip_dev_notifier);
874f3a0592bSStephen Hemminger register_inetaddr_notifier(&clip_inet_notifier);
8751da177e4SLinus Torvalds
876ba421793SKees Cook timer_setup(&idle_timer, idle_timer_check, 0);
8772d907392SStephen Hemminger
87824781734SAdrian Bunk #ifdef CONFIG_PROC_FS
87924781734SAdrian Bunk {
88024781734SAdrian Bunk struct proc_dir_entry *p;
88124781734SAdrian Bunk
882c3506372SChristoph Hellwig p = proc_create_net("arp", 0444, atm_proc_root, &arp_seq_ops,
883c3506372SChristoph Hellwig sizeof(struct clip_seq_state));
884dbee0d3fSWang Chen if (!p) {
88599824461SJoe Perches pr_err("Unable to initialize /proc/net/atm/arp\n");
886dbee0d3fSWang Chen atm_clip_exit_noproc();
887dbee0d3fSWang Chen return -ENOMEM;
888dbee0d3fSWang Chen }
88924781734SAdrian Bunk }
89024781734SAdrian Bunk #endif
8911da177e4SLinus Torvalds
8921da177e4SLinus Torvalds return 0;
8931da177e4SLinus Torvalds }
8941da177e4SLinus Torvalds
atm_clip_exit_noproc(void)895dbee0d3fSWang Chen static void atm_clip_exit_noproc(void)
8961da177e4SLinus Torvalds {
8971da177e4SLinus Torvalds struct net_device *dev, *next;
8981da177e4SLinus Torvalds
899f3a0592bSStephen Hemminger unregister_inetaddr_notifier(&clip_inet_notifier);
900f3a0592bSStephen Hemminger unregister_netdevice_notifier(&clip_dev_notifier);
901f3a0592bSStephen Hemminger
9021da177e4SLinus Torvalds deregister_atm_ioctl(&clip_ioctl_ops);
9031da177e4SLinus Torvalds
9041da177e4SLinus Torvalds /* First, stop the idle timer, so it stops banging
9051da177e4SLinus Torvalds * on the table.
9061da177e4SLinus Torvalds */
9072d907392SStephen Hemminger del_timer_sync(&idle_timer);
9081da177e4SLinus Torvalds
9091da177e4SLinus Torvalds dev = clip_devs;
9101da177e4SLinus Torvalds while (dev) {
9111da177e4SLinus Torvalds next = PRIV(dev)->next;
9121da177e4SLinus Torvalds unregister_netdev(dev);
9131da177e4SLinus Torvalds free_netdev(dev);
9141da177e4SLinus Torvalds dev = next;
9151da177e4SLinus Torvalds }
9161da177e4SLinus Torvalds }
9171da177e4SLinus Torvalds
atm_clip_exit(void)918dbee0d3fSWang Chen static void __exit atm_clip_exit(void)
919dbee0d3fSWang Chen {
920dbee0d3fSWang Chen remove_proc_entry("arp", atm_proc_root);
921dbee0d3fSWang Chen
922dbee0d3fSWang Chen atm_clip_exit_noproc();
923dbee0d3fSWang Chen }
924dbee0d3fSWang Chen
9251da177e4SLinus Torvalds module_init(atm_clip_init);
9261da177e4SLinus Torvalds module_exit(atm_clip_exit);
9274909e488SStephen Hemminger MODULE_AUTHOR("Werner Almesberger");
9284909e488SStephen Hemminger MODULE_DESCRIPTION("Classical/IP over ATM interface");
9291da177e4SLinus Torvalds MODULE_LICENSE("GPL");
930