1 diff -Nur linux.old/net/atm/br2684.c linux.new/net/atm/br2684.c
2 --- linux.old/net/atm/br2684.c 2004-08-08 01:26:06.000000000 +0200
3 +++ linux.new/net/atm/br2684.c 2005-11-13 00:04:15.000000000 +0100
6 #include <asm/uaccess.h>
8 -#include <linux/atm.h>
9 -#include <linux/atmdev.h>
11 #include <linux/atmbr2684.h>
18 #define skb_debug(skb) do {} while (0)
21 +#define BR2684_LLC_LEN 3
22 +#define BR2684_SNAP_LEN 3
23 +#define BR2684_ETHERTYPE_LEN 2
24 +#define BR2684_PID_LEN 2
25 +#define BR2684_PAD_LEN 2
27 +static unsigned char llc_common[] = { 0xaa, 0xaa, 0x03 };
28 +static unsigned char snap_bridged[] = { 0x00, 0x80, 0xc2 };
29 +static unsigned char snap_routed[] = { 0x00, 0x00, 0x00 };
30 +static unsigned char pid_ipv4[] = { 0x00, 0x07 };
31 +static unsigned char ethertype_ipv4[] = { 0x08, 0x00 };
32 +static unsigned char ethertype_ipv6[] = { 0x86, 0xdd };
33 +static unsigned char pad_bridged[] = { 0x00, 0x00 };
35 static unsigned char llc_oui_pid_pad[] =
36 { 0xAA, 0xAA, 0x03, 0x00, 0x80, 0xC2, 0x00, 0x07, 0x00, 0x00 };
37 +static unsigned char llc_oui_ipv6[] =
38 + { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd };
39 +static unsigned char llc_oui_ipv4[] =
40 + { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00 };
44 - e_vc = BR2684_ENCAPS_VC,
45 + e_vc = BR2684_ENCAPS_VC,
46 e_llc = BR2684_ENCAPS_LLC,
52 - struct atm_vcc *atmvcc;
53 + struct atm_vcc *atmvcc;
54 struct br2684_dev *brdev;
55 /* keep old push,pop functions for chaining */
56 - void (*old_push)(struct atm_vcc *vcc,struct sk_buff *skb);
57 + void (*old_push) (struct atm_vcc * vcc, struct sk_buff * skb);
58 /* void (*old_pop)(struct atm_vcc *vcc,struct sk_buff *skb); */
59 enum br2684_encaps encaps;
60 + enum br2684_payload payload;
61 struct list_head brvccs;
62 #ifdef CONFIG_ATM_BR2684_IPFILTER
63 struct br2684_filter filter;
64 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
65 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
66 #ifndef FASTER_VERSION
67 unsigned copies_needed, copies_failed;
68 -#endif /* FASTER_VERSION */
69 +#endif /* FASTER_VERSION */
73 struct net_device net_dev;
74 struct list_head br2684_devs;
76 - struct list_head brvccs; /* one device <=> one vcc (before xmas) */
77 + struct list_head brvccs; /* one device <=> one vcc (before xmas) */
78 struct net_device_stats stats;
85 - skb_push(skb, minheadroom);
86 - if (brvcc->encaps == e_llc)
87 - memcpy(skb->data, llc_oui_pid_pad, 10);
89 - memset(skb->data, 0, 2);
90 -#endif /* FASTER_VERSION */
92 + /* This skb_push is a problem: routed packets need less headroom than
96 +/* skb_push(skb, minheadroom); */
97 + if (brvcc->encaps == e_llc) {
99 + int actual_headroom;
104 + ((brvcc->payload == p_bridged) ?
105 + (BR2684_PID_LEN + BR2684_PAD_LEN) :
106 + BR2684_ETHERTYPE_LEN);
108 + skb_push(skb, actual_headroom);
109 + memcpy(skb->data, llc_common, BR2684_LLC_LEN);
110 + offset += BR2684_LLC_LEN;
112 + if (brvcc->payload == p_bridged) {
113 + memcpy(skb->data + offset, snap_bridged,
115 + offset += BR2684_SNAP_LEN;
116 + /* pid_ipv4 is poorly named. should probably be
119 + memcpy(skb->data + offset, pid_ipv4,
121 + offset += BR2684_PID_LEN;
122 + memcpy(skb->data + offset, pad_bridged,
124 + offset += BR2684_PAD_LEN;
125 + } else if (brvcc->payload == p_routed) {
126 + unsigned short prot =
127 + __constant_ntohs(skb->protocol);
128 + memcpy(skb->data + offset, snap_routed,
130 + offset += BR2684_SNAP_LEN;
134 + memcpy(skb->data + offset,
136 + BR2684_ETHERTYPE_LEN);
139 + memcpy(skb->data + offset,
141 + BR2684_ETHERTYPE_LEN);
144 + dev_kfree_skb(skb);
147 + offset += BR2684_ETHERTYPE_LEN;
152 + if (brvcc->payload == p_bridged)
153 + memset(skb->data, 0, 2);
155 +#endif /* FASTER_VERSION */
158 ATM_SKB(skb)->vcc = atmvcc = brvcc->atmvcc;
159 - DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->dev);
160 + DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc,
162 if (!atm_may_send(atmvcc, skb->truesize)) {
163 /* we free this here for now, because we cannot know in a higher
164 - layer whether the skb point it supplied wasn't freed yet.
167 + layer whether the skb point it supplied wasn't freed yet.
174 atomic_add(skb->truesize, &atmvcc->sk->wmem_alloc);
175 ATM_SKB(skb)->atm_options = atmvcc->atm_options;
176 brdev->stats.tx_packets++;
177 @@ -428,18 +512,39 @@
178 atm_return(atmvcc, skb->truesize);
179 DPRINTK("skb from brdev %p\n", brdev);
180 if (brvcc->encaps == e_llc) {
181 + /* accept packets that have "ipv[46]" in the snap header */
182 + /* 8 - 2 == sizeof(llc_oui_ipv6) - BR2684_ETHERTYPE_LEN */
183 + if (memcmp(skb->data, llc_oui_ipv6, 8 - 2) == 0) {
184 + plen = sizeof(llc_oui_ipv6);
186 + if (memcmp(skb->data + 6, ethertype_ipv6, 2) == 0)
188 + __constant_htons(ETH_P_IPV6);
189 + else if (memcmp(skb->data + 6, ethertype_ipv4, 2)
191 + skb->protocol = __constant_htons(ETH_P_IP);
193 + brdev->stats.rx_errors++;
194 + dev_kfree_skb(skb);
197 + skb_pull(skb, plen);
198 + skb->nh.raw = skb->data;
199 + skb->pkt_type = PACKET_HOST;
202 /* let us waste some time for checking the encapsulation.
203 Note, that only 7 char is checked so frames with a valid FCS
204 are also accepted (but FCS is not checked of course) */
205 - if (memcmp(skb->data, llc_oui_pid_pad, 7)) {
206 + else if (memcmp(skb->data, llc_oui_pid_pad, 7) == 0) {
207 + skb_pull(skb, plen - ETH_HLEN);
209 + eth_type_trans(skb, &brdev->net_dev);
211 brdev->stats.rx_errors++;
216 - /* Strip FCS if present */
217 - if (skb->len > 7 && skb->data[7] == 0x01)
218 - __skb_trim(skb, skb->len - 4);
220 plen = PADLEN + ETH_HLEN; /* pad, dstmac,srcmac, ethtype */
221 /* first 2 chars should be 0 */
222 @@ -448,13 +553,14 @@
226 + skb_pull(skb, plen - ETH_HLEN);
227 + skb->protocol = eth_type_trans(skb, &brdev->net_dev);
229 if (skb->len < plen) {
230 brdev->stats.rx_errors++;
231 dev_kfree_skb(skb); /* dev_ not needed? */
235 #ifdef FASTER_VERSION
236 /* FIXME: tcpdump shows that pointer to mac header is 2 bytes earlier,
237 than should be. What else should I set? */
238 @@ -465,30 +571,29 @@
239 skb->protocol = ((u16 *) skb->data)[-1];
240 #else /* some protocols might require this: */
241 skb->protocol = br_type_trans(skb, &brdev->net_dev);
242 -#endif /* CONFIG_BR2684_FAST_TRANS */
243 +#endif /* CONFIG_BR2684_FAST_TRANS */
245 - skb_pull(skb, plen - ETH_HLEN);
246 - skb->protocol = eth_type_trans(skb, &brdev->net_dev);
247 -#endif /* FASTER_VERSION */
248 + /* skb_pull(skb, plen - ETH_HLEN); */
249 + /* skb->protocol = eth_type_trans(skb, &brdev->net_dev); */
250 +#endif /* FASTER_VERSION */
251 #ifdef CONFIG_ATM_BR2684_IPFILTER
252 if (packet_fails_filter(skb->protocol, brvcc, skb)) {
253 brdev->stats.rx_dropped++;
257 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
258 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
259 skb->dev = &brdev->net_dev;
260 - ATM_SKB(skb)->vcc = atmvcc; /* needed ? */
261 + /* ATM_SKB(skb)->vcc = atmvcc; *//* needed ? */
262 DPRINTK("received packet's protocol: %x\n", ntohs(skb->protocol));
264 - if (!(brdev->net_dev.flags & IFF_UP)) { /* sigh, interface is down */
265 + if (!(brdev->net_dev.flags & IFF_UP)) { /* sigh, interface is down */
266 brdev->stats.rx_dropped++;
270 brdev->stats.rx_packets++;
271 brdev->stats.rx_bytes += skb->len;
272 - memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
276 @@ -525,10 +630,10 @@
280 - if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO ||
281 - be.fcs_auto || be.has_vpiid || be.send_padding || (be.encaps !=
282 - BR2684_ENCAPS_VC && be.encaps != BR2684_ENCAPS_LLC) ||
283 - be.min_size != 0) {
284 + if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO
285 + || be.fcs_auto || be.has_vpiid || be.send_padding
286 + || (be.encaps != BR2684_ENCAPS_VC
287 + && be.encaps != BR2684_ENCAPS_LLC) || be.min_size != 0) {
291 @@ -554,18 +659,21 @@
292 brvcc->atmvcc = atmvcc;
293 atmvcc->user_back = brvcc;
294 brvcc->encaps = (enum br2684_encaps) be.encaps;
295 + brvcc->payload = (enum br2684_payload) be.payload;
296 brvcc->old_push = atmvcc->push;
298 atmvcc->push = br2684_push;
299 skb_queue_head_init(©);
300 skb_migrate(&atmvcc->sk->receive_queue, ©);
301 while ((skb = skb_dequeue(©))) {
303 BRPRIV(skb->dev)->stats.rx_bytes -= skb->len;
304 BRPRIV(skb->dev)->stats.rx_packets--;
306 br2684_push(atmvcc, skb);
311 write_unlock_irq(&devs_lock);
314 @@ -608,12 +717,25 @@
316 if (ni.ifname[0] != '\0') {
317 memcpy(brdev->net_dev.name, ni.ifname,
318 - sizeof(brdev->net_dev.name));
319 - brdev->net_dev.name[sizeof(brdev->net_dev.name) - 1] = '\0';
320 + sizeof(brdev->net_dev.name));
321 + brdev->net_dev.name[sizeof(brdev->net_dev.name) - 1] =
324 sprintf(brdev->net_dev.name, "nas%d", brdev->number);
325 DPRINTK("registered netdev %s\n", brdev->net_dev.name);
326 - ether_setup(&brdev->net_dev);
327 + if (ni.payload == p_routed) {
328 + brdev->net_dev.hard_header_len = 0;
329 + brdev->net_dev.addr_len = 0;
330 + brdev->net_dev.mtu = 1500;
332 + /* Type PPP seems most suitable */
333 + brdev->net_dev.type = ARPHRD_PPP;
334 + brdev->net_dev.flags =
335 + IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
336 + brdev->net_dev.tx_queue_len = 100;
338 + ether_setup(&brdev->net_dev);
340 brdev->mac_was_set = 0;
341 #ifdef FASTER_VERSION
342 my_eth_header = brdev->net_dev.hard_header;
343 @@ -677,12 +799,11 @@
344 err = br2684_setfilt(atmvcc, arg);
347 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
348 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
353 -#ifdef CONFIG_PROC_FS
354 /* Never put more than 256 bytes in at once */
355 static int br2684_proc_engine(loff_t pos, char *buf)
357 @@ -692,52 +813,62 @@
358 list_for_each(lhd, &br2684_devs) {
359 brdev = list_entry_brdev(lhd);
361 - return sprintf(buf, "dev %.16s: num=%d, mac=%02X:%02X:"
362 - "%02X:%02X:%02X:%02X (%s)\n", brdev->net_dev.name,
364 - brdev->net_dev.dev_addr[0],
365 - brdev->net_dev.dev_addr[1],
366 - brdev->net_dev.dev_addr[2],
367 - brdev->net_dev.dev_addr[3],
368 - brdev->net_dev.dev_addr[4],
369 - brdev->net_dev.dev_addr[5],
370 - brdev->mac_was_set ? "set" : "auto");
371 + return sprintf(buf,
372 + "dev %.16s: num=%d, mac=%02X:%02X:"
373 + "%02X:%02X:%02X:%02X (%s)\n",
374 + brdev->net_dev.name, brdev->number,
375 + brdev->net_dev.dev_addr[0],
376 + brdev->net_dev.dev_addr[1],
377 + brdev->net_dev.dev_addr[2],
378 + brdev->net_dev.dev_addr[3],
379 + brdev->net_dev.dev_addr[4],
380 + brdev->net_dev.dev_addr[5],
382 + mac_was_set ? "set" : "auto");
383 list_for_each(lhc, &brdev->brvccs) {
384 brvcc = list_entry_brvcc(lhc);
386 - return sprintf(buf, " vcc %d.%d.%d: encaps=%s"
387 + return sprintf(buf,
388 + " vcc %d.%d.%d: encaps=%s"
390 #ifndef FASTER_VERSION
391 - ", failed copies %u/%u"
392 -#endif /* FASTER_VERSION */
393 - "\n", brvcc->atmvcc->dev->number,
394 - brvcc->atmvcc->vpi, brvcc->atmvcc->vci,
395 - (brvcc->encaps == e_llc) ? "LLC" : "VC"
396 + ", failed copies %u/%u"
397 +#endif /* FASTER_VERSION */
399 + brvcc->atmvcc->dev->number,
400 + brvcc->atmvcc->vpi,
401 + brvcc->atmvcc->vci,
403 + e_llc) ? "LLC" : "VC",
405 + p_bridged) ? "bridged" :
407 #ifndef FASTER_VERSION
408 - , brvcc->copies_failed
409 - , brvcc->copies_needed
410 -#endif /* FASTER_VERSION */
411 + , brvcc->copies_failed,
412 + brvcc->copies_needed
413 +#endif /* FASTER_VERSION */
415 #ifdef CONFIG_ATM_BR2684_IPFILTER
416 #define b1(var, byte) ((u8 *) &brvcc->filter.var)[byte]
417 #define bs(var) b1(var, 0), b1(var, 1), b1(var, 2), b1(var, 3)
418 if (brvcc->filter.netmask != 0 && pos-- == 0)
419 - return sprintf(buf, " filter=%d.%d.%d.%d/"
420 - "%d.%d.%d.%d\n", bs(prefix), bs(netmask));
421 + return sprintf(buf,
422 + " filter=%d.%d.%d.%d/"
423 + "%d.%d.%d.%d\n", bs(prefix),
427 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
428 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
434 static ssize_t br2684_proc_read(struct file *file, char *buf, size_t count,
439 int len = 0, x, left;
442 page = get_free_page(GFP_KERNEL);
447 read_lock(&devs_lock);
449 - x = br2684_proc_engine(n, &((char *) page)[len]);
450 + x = br2684_proc_engine(*pos, &((char *) page)[len]);
454 @@ -761,12 +892,11 @@
463 read_unlock(&devs_lock);
465 if (len > 0 && copy_to_user(buf, (char *) page, len))
468 @@ -774,34 +904,32 @@
471 static struct file_operations br2684_proc_operations = {
472 - read: br2684_proc_read,
473 + read:br2684_proc_read,
476 extern struct proc_dir_entry *atm_proc_root; /* from proc.c */
477 -#endif /* CONFIG_PROC_FS */
479 +extern int (*br2684_ioctl_hook) (struct atm_vcc *, unsigned int,
482 /* the following avoids some spurious warnings from the compiler */
483 #define UNUSED __attribute__((unused))
485 static int __init UNUSED br2684_init(void)
487 -#ifdef CONFIG_PROC_FS
488 struct proc_dir_entry *p;
489 if ((p = create_proc_entry("br2684", 0, atm_proc_root)) == NULL)
491 p->proc_fops = &br2684_proc_operations;
492 -#endif /* CONFIG_PROC_FS */
493 - br2684_ioctl_set(br2684_ioctl);
494 + br2684_ioctl_hook = br2684_ioctl;
498 static void __exit UNUSED br2684_exit(void)
500 struct br2684_dev *brdev;
501 - br2684_ioctl_set(NULL);
502 -#ifdef CONFIG_PROC_FS
503 + br2684_ioctl_hook = NULL;
504 remove_proc_entry("br2684", atm_proc_root);
505 -#endif /* CONFIG_PROC_FS */
506 while (!list_empty(&br2684_devs)) {
507 brdev = list_entry_brdev(br2684_devs.next);
508 unregister_netdev(&brdev->net_dev);
509 diff -Nur linux.old/net/atm/common.c linux.new/net/atm/common.c
510 --- linux.old/net/atm/common.c 2004-02-18 14:36:32.000000000 +0100
511 +++ linux.new/net/atm/common.c 2005-11-13 00:46:11.000000000 +0100
514 #ifdef CONFIG_ATM_BR2684_MODULE
515 EXPORT_SYMBOL(br2684_ioctl_set);
516 +EXPORT_SYMBOL(br2684_ioctl_hook);
520 diff -Nur linux.old/include/linux/atmbr2684.h linux.new/include/linux/atmbr2684.h
521 --- linux.old/include/linux/atmbr2684.h 2005-11-13 00:28:19.000000000 +0100
522 +++ linux.new/include/linux/atmbr2684.h 2005-11-13 00:06:42.000000000 +0100
525 #include <linux/atm.h>
526 #include <linux/if.h> /* For IFNAMSIZ */
527 +#include <linux/if_ether.h> /* ETH_P_* */
530 * Type of media we're bridging (ethernet, token ring, etc) Currently only
532 #define BR2684_ENCAPS_AUTODETECT (2) /* Unsuported */
535 + * Is this VC bridged or routed?
538 +#define BR2684_PAYLOAD_ROUTED (0)
539 +#define BR2684_PAYLOAD_BRIDGED (1)
543 * This is for the ATM_NEWBACKENDIF call - these are like socket families:
544 * the first element of the structure is the backend number and the rest
545 * is per-backend specific
547 struct atm_newif_br2684 {
548 - atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
549 - int media; /* BR2684_MEDIA_* */
550 - char ifname[IFNAMSIZ];
552 + atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
553 + int media; /* BR2684_MEDIA_* */
554 + char ifname[IFNAMSIZ];
556 + int payload; /* bridged or routed */
561 * is per-backend specific
563 struct atm_backend_br2684 {
564 - atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
565 + atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
566 struct br2684_if_spec ifspec;
567 - int fcs_in; /* BR2684_FCSIN_* */
568 - int fcs_out; /* BR2684_FCSOUT_* */
569 - int fcs_auto; /* 1: fcs_{in,out} disabled if no FCS rx'ed */
570 - int encaps; /* BR2684_ENCAPS_* */
571 - int has_vpiid; /* 1: use vpn_id - Unsupported */
573 - int send_padding; /* unsupported */
574 - int min_size; /* we will pad smaller packets than this */
575 + int fcs_in; /* BR2684_FCSIN_* */
576 + int fcs_out; /* BR2684_FCSOUT_* */
577 + int fcs_auto; /* 1: fcs_{in,out} disabled if no FCS rx'ed */
578 + int encaps; /* BR2684_ENCAPS_* */
579 + int payload; /* BR2684_PAYLOAD_* */
580 + int has_vpiid; /* 1: use vpn_id - Unsupported */
582 + int send_padding; /* unsupported */
583 + int min_size; /* we will pad smaller packets than this */
588 struct br2684_filter filter;
591 +enum br2684_payload {
592 + p_routed = BR2684_PAYLOAD_ROUTED,
593 + p_bridged = BR2684_PAYLOAD_BRIDGED,
596 #define BR2684_SETFILT _IOW( 'a', ATMIOC_BACKEND + 0, \
597 struct br2684_filter_set)
599 -#endif /* _LINUX_ATMBR2684_H */
600 +#endif /* _LINUX_ATMBR2684_H */