5 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
7 #include <linux/string.h>
8 #include <linux/errno.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
12 #include <linux/netdevice.h>
14 #include <linux/wait.h>
16 #include <linux/if_arp.h>
18 #include <linux/atm.h>
19 #include <linux/atmdev.h>
22 #include <linux/capability.h>
27 #include <linux/bitops.h>
28 #include <linux/poison.h>
33 #include <linux/slab.h>
39 #include <asm/byteorder.h>
49 static const struct neigh_ops clip_neigh_ops;
67 atm_force_charge(atmarpd, skb->
truesize);
77 pr_debug(
"%p to entry %p (neigh %p)\n", clip_vcc, entry, entry->
neigh);
81 entry->
vccs = clip_vcc;
88 struct clip_vcc **walk;
91 pr_crit(
"!clip_vcc->entry (clip_vcc %p)\n", clip_vcc);
94 netif_tx_lock_bh(entry->
neigh->dev);
96 for (walk = &entry->
vccs; *walk; walk = &(*walk)->
next)
97 if (*walk == clip_vcc) {
100 *walk = clip_vcc->
next;
103 netif_wake_queue(entry->
neigh->dev);
111 pr_crit(
"neigh_update failed with %d\n", error);
114 pr_crit(
"ATMARP: failed (entry %p, vcc 0x%p)\n", entry, clip_vcc);
116 netif_tx_unlock_bh(entry->
neigh->dev);
120 static int neigh_check_cb(
struct neighbour *
n)
125 if (n->
ops != &clip_neigh_ops)
127 for (cv = entry->
vccs; cv; cv = cv->
next) {
131 pr_debug(
"releasing vcc %p->%p of entry %p\n",
143 pr_debug(
"destruction postponed with ref %d\n",
156 static void idle_timer_check(
unsigned long dummy)
164 static int clip_arp_rcv(
struct sk_buff *skb)
180 static const unsigned char llc_oui[] = {
191 struct clip_vcc *clip_vcc =
CLIP_VCC(vcc);
202 pr_debug(
"removing VCC %p\n", clip_vcc);
204 unlink_clip_vcc(clip_vcc);
210 skb->
dev = clip_vcc->
entry ? clip_vcc->
entry->neigh->dev : clip_devs;
217 skb_reset_mac_header(skb);
218 if (!clip_vcc->
encap ||
226 skb->
dev->stats.rx_packets++;
227 skb->
dev->stats.rx_bytes += skb->
len;
233 skb->
dev->stats.rx_packets++;
234 skb->
dev->stats.rx_bytes += skb->
len;
246 struct clip_vcc *clip_vcc =
CLIP_VCC(vcc);
257 if (atm_may_send(vcc, 0)) {
260 netif_wake_queue(dev);
262 spin_unlock_irqrestore(&
PRIV(dev)->xoff_lock, flags);
265 static void clip_neigh_solicit(
struct neighbour *neigh,
struct sk_buff *skb)
269 pr_debug(
"(neigh %p, skb %p)\n", neigh, skb);
275 #ifndef CONFIG_ATM_CLIP_NO_ICMP
281 static const struct neigh_ops clip_neigh_ops = {
283 .solicit = clip_neigh_solicit,
284 .error_report = clip_neigh_error,
289 static int clip_constructor(
struct neighbour *neigh)
300 neigh->
ops = &clip_neigh_ops;
318 static int clip_encap(
struct atm_vcc *vcc,
int mode)
339 pr_err(
"skb_dst(skb) == NULL\n");
341 dev->
stats.tx_dropped++;
344 rt = (
struct rtable *) dst;
348 daddr = &ip_hdr(skb)->daddr;
349 n = dst_neigh_lookup(dst, daddr);
351 pr_err(
"NO NEIGHBOUR !\n");
353 dev->
stats.tx_dropped++;
356 entry = neighbour_priv(n);
367 dev->
stats.tx_dropped++;
369 goto out_release_neigh;
373 pr_debug(
"using neighbour %p, vcc %p\n", n, vcc);
374 if (entry->
vccs->encap) {
378 memcpy(here, llc_oui,
sizeof(llc_oui));
384 pr_debug(
"atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->
dev);
388 goto out_release_neigh;
390 dev->
stats.tx_packets++;
393 if (atm_may_send(vcc, 0)) {
394 entry->
vccs->xoff = 0;
395 goto out_release_neigh;
398 netif_stop_queue(dev);
400 if (!entry->
vccs->xoff)
401 netif_start_queue(dev);
406 spin_unlock_irqrestore(&clip_priv->
xoff_lock, flags);
412 static int clip_mkip(
struct atm_vcc *vcc,
int timeout)
414 struct clip_vcc *clip_vcc;
421 pr_debug(
"%p vcc %p\n", clip_vcc, vcc);
432 vcc->
push = clip_push;
446 struct clip_vcc *clip_vcc;
449 if (vcc->
push != clip_push) {
455 if (!clip_vcc->
entry) {
456 pr_err(
"hiding hidden ATMARP entry\n");
460 unlink_clip_vcc(clip_vcc);
463 rt = ip_route_output(&
init_net, ip, 0, 1, 0);
466 neigh = __neigh_lookup(&
arp_tbl, &ip, rt->
dst.dev, 1);
470 entry = neighbour_priv(neigh);
471 if (entry != clip_vcc->
entry) {
472 if (!clip_vcc->
entry)
476 unlink_clip_vcc(clip_vcc);
478 link_vcc(clip_vcc, entry);
482 neigh_release(neigh);
487 .ndo_start_xmit = clip_start_xmit,
488 .ndo_neigh_construct = clip_constructor,
491 static void clip_setup(
struct net_device *dev)
507 static int clip_create(
int number)
510 struct clip_priv *clip_priv;
514 for (dev = clip_devs;
dev; dev =
PRIV(dev)->next)
519 for (dev = clip_devs;
dev; dev =
PRIV(dev)->next)
521 number =
PRIV(dev)->number + 1;
523 dev =
alloc_netdev(
sizeof(
struct clip_priv),
"", clip_setup);
526 clip_priv =
PRIV(dev);
535 clip_priv->
next = clip_devs;
546 if (!net_eq(dev_net(dev), &
init_net))
574 static int clip_inet_event(
struct notifier_block *
this,
unsigned long event,
577 struct in_device *in_dev;
579 in_dev = ((
struct in_ifaddr *)ifa)->ifa_dev;
590 .notifier_call = clip_device_event,
596 .notifier_call = clip_inet_event,
601 static void atmarpd_close(
struct atm_vcc *vcc)
615 .close = atmarpd_close
619 static struct atm_dev atmarpd_dev = {
620 .ops = &atmarpd_dev_ops,
627 static int atm_init_atmarp(
struct atm_vcc *vcc)
641 vcc->
dev = &atmarpd_dev;
650 static int clip_ioctl(
struct socket *
sock,
unsigned int cmd,
unsigned long arg)
652 struct atm_vcc *vcc = ATM_SD(sock);
670 err = clip_create(arg);
673 err = atm_init_atmarp(vcc);
680 err = clip_mkip(vcc, arg);
686 err = clip_encap(vcc, arg);
692 static struct atm_ioctl clip_ioctl_ops = {
697 #ifdef CONFIG_PROC_FS
701 static int code[] = { 1, 2, 10, 6, 1, 0 };
702 static int e164[] = { 1, 8, 4, 6, 1, 0 };
704 if (*addr->sas_addr.
pub) {
706 if (*addr->sas_addr.
prv)
708 }
else if (!*addr->sas_addr.
prv) {
712 if (*addr->sas_addr.
prv) {
713 unsigned char *prv = addr->sas_addr.
prv;
718 for (i = 0; fields[
i]; i++) {
719 for (j = fields[i];
j; j--)
728 #define SEQ_NO_VCC_TOKEN ((void *) 2)
738 svc = ((clip_vcc == SEQ_NO_VCC_TOKEN) ||
741 llc = ((clip_vcc == SEQ_NO_VCC_TOKEN) || clip_vcc->
encap);
743 if (clip_vcc == SEQ_NO_VCC_TOKEN)
744 exp = entry->
neigh->used;
751 dev->
name, svc ?
"SVC" :
"PVC", llc ?
"LLC" :
"NULL", exp);
759 if (clip_vcc == SEQ_NO_VCC_TOKEN) {
767 clip_vcc->
vcc->dev->number,
768 clip_vcc->
vcc->vpi, clip_vcc->
vcc->vci);
770 svc_addr(seq, &clip_vcc->
vcc->remote);
775 struct clip_seq_state {
780 struct clip_vcc *
vcc;
783 static struct clip_vcc *clip_seq_next_vcc(
struct atmarp_entry *
e,
784 struct clip_vcc *
curr)
789 return SEQ_NO_VCC_TOKEN;
792 if (curr == SEQ_NO_VCC_TOKEN)
800 static void *clip_seq_vcc_walk(
struct clip_seq_state *
state,
803 struct clip_vcc *vcc = state->vcc;
805 vcc = clip_seq_next_vcc(e, vcc);
806 if (vcc && pos !=
NULL) {
808 vcc = clip_seq_next_vcc(e, vcc);
822 struct clip_seq_state *state = (
struct clip_seq_state *)_state;
827 return clip_seq_vcc_walk(state, neighbour_priv(n), pos);
830 static void *clip_seq_start(
struct seq_file *seq, loff_t * pos)
832 struct clip_seq_state *state = seq->
private;
833 state->ns.neigh_sub_iter = clip_seq_sub_iter;
837 static int clip_seq_show(
struct seq_file *seq,
void *
v)
839 static char atm_arp_banner[] =
840 "IPitf TypeEncp Idle IP address ATM address\n";
845 struct clip_seq_state *state = seq->
private;
846 struct clip_vcc *vcc = state->vcc;
849 atmarp_info(seq, n, neighbour_priv(n), vcc);
855 .
start = clip_seq_start,
858 .show = clip_seq_show,
864 sizeof(
struct clip_seq_state));
868 .
open = arp_seq_open,
876 static void atm_clip_exit_noproc(
void);
878 static int __init atm_clip_init(
void)
886 #ifdef CONFIG_PROC_FS
892 pr_err(
"Unable to initialize /proc/net/atm/arp\n");
893 atm_clip_exit_noproc();
902 static void atm_clip_exit_noproc(
void)
918 next =
PRIV(dev)->next;
925 static void __exit atm_clip_exit(
void)
929 atm_clip_exit_noproc();