1 diff -urN linux-2.4.32/net/atm/br2684.c linux-2.4.32.new/net/atm/br2684.c
2 --- linux-2.4.32/net/atm/br2684.c 2004-08-08 01:26:06.000000000 +0200
3 +++ linux-2.4.32.new/net/atm/br2684.c 2006-02-06 18:59:40.000000000 +0100
5 #define skb_debug(skb) do {} while (0)
8 +#define BR2684_LLC_LEN 3
9 +#define BR2684_SNAP_LEN 3
10 +#define BR2684_ETHERTYPE_LEN 2
11 +#define BR2684_PID_LEN 2
12 +#define BR2684_PAD_LEN 2
14 +static unsigned char llc_common[] = { 0xaa, 0xaa, 0x03 };
15 +static unsigned char snap_bridged[] = { 0x00, 0x80, 0xc2 };
16 +static unsigned char snap_routed[] = { 0x00, 0x00, 0x00 };
17 +static unsigned char pid_ipv4[] = { 0x00, 0x07 };
18 +static unsigned char ethertype_ipv4[] = { 0x08, 0x00 };
19 +static unsigned char ethertype_ipv6[] = { 0x86, 0xdd };
20 +static unsigned char pad_bridged[] = { 0x00, 0x00 };
22 static unsigned char llc_oui_pid_pad[] =
23 { 0xAA, 0xAA, 0x03, 0x00, 0x80, 0xC2, 0x00, 0x07, 0x00, 0x00 };
24 +static unsigned char llc_oui_ipv6[] =
25 + { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd };
26 +static unsigned char llc_oui_ipv4[] =
27 + { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00 };
31 - e_vc = BR2684_ENCAPS_VC,
32 + e_vc = BR2684_ENCAPS_VC,
33 e_llc = BR2684_ENCAPS_LLC,
37 - struct atm_vcc *atmvcc;
38 + struct atm_vcc *atmvcc;
39 struct br2684_dev *brdev;
40 /* keep old push,pop functions for chaining */
41 - void (*old_push)(struct atm_vcc *vcc,struct sk_buff *skb);
42 + void (*old_push) (struct atm_vcc * vcc, struct sk_buff * skb);
43 /* void (*old_pop)(struct atm_vcc *vcc,struct sk_buff *skb); */
44 enum br2684_encaps encaps;
45 + enum br2684_payload payload;
46 struct list_head brvccs;
47 #ifdef CONFIG_ATM_BR2684_IPFILTER
48 struct br2684_filter filter;
49 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
50 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
51 #ifndef FASTER_VERSION
52 unsigned copies_needed, copies_failed;
53 -#endif /* FASTER_VERSION */
54 +#endif /* FASTER_VERSION */
58 struct net_device net_dev;
59 struct list_head br2684_devs;
61 - struct list_head brvccs; /* one device <=> one vcc (before xmas) */
62 + struct list_head brvccs; /* one device <=> one vcc (before xmas) */
63 struct net_device_stats stats;
70 - skb_push(skb, minheadroom);
71 - if (brvcc->encaps == e_llc)
72 - memcpy(skb->data, llc_oui_pid_pad, 10);
74 - memset(skb->data, 0, 2);
75 -#endif /* FASTER_VERSION */
77 + /* This skb_push is a problem: routed packets need less headroom than
81 +/* skb_push(skb, minheadroom); */
82 + if (brvcc->encaps == e_llc) {
84 + int actual_headroom;
89 + ((brvcc->payload == p_bridged) ?
90 + (BR2684_PID_LEN + BR2684_PAD_LEN) :
91 + BR2684_ETHERTYPE_LEN);
93 + skb_push(skb, actual_headroom);
94 + memcpy(skb->data, llc_common, BR2684_LLC_LEN);
95 + offset += BR2684_LLC_LEN;
97 + if (brvcc->payload == p_bridged) {
98 + memcpy(skb->data + offset, snap_bridged,
100 + offset += BR2684_SNAP_LEN;
101 + /* pid_ipv4 is poorly named. should probably be
104 + memcpy(skb->data + offset, pid_ipv4,
106 + offset += BR2684_PID_LEN;
107 + memcpy(skb->data + offset, pad_bridged,
109 + offset += BR2684_PAD_LEN;
110 + } else if (brvcc->payload == p_routed) {
111 + unsigned short prot =
112 + __constant_ntohs(skb->protocol);
113 + memcpy(skb->data + offset, snap_routed,
115 + offset += BR2684_SNAP_LEN;
119 + memcpy(skb->data + offset,
121 + BR2684_ETHERTYPE_LEN);
124 + memcpy(skb->data + offset,
126 + BR2684_ETHERTYPE_LEN);
129 + dev_kfree_skb(skb);
132 + offset += BR2684_ETHERTYPE_LEN;
137 + if (brvcc->payload == p_bridged)
138 + memset(skb->data, 0, 2);
140 +#endif /* FASTER_VERSION */
143 ATM_SKB(skb)->vcc = atmvcc = brvcc->atmvcc;
144 - DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->dev);
145 + DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc,
147 if (!atm_may_send(atmvcc, skb->truesize)) {
148 /* we free this here for now, because we cannot know in a higher
149 - layer whether the skb point it supplied wasn't freed yet.
152 + layer whether the skb point it supplied wasn't freed yet.
159 atomic_add(skb->truesize, &atmvcc->sk->wmem_alloc);
160 ATM_SKB(skb)->atm_options = atmvcc->atm_options;
161 brdev->stats.tx_packets++;
162 @@ -428,18 +507,39 @@
163 atm_return(atmvcc, skb->truesize);
164 DPRINTK("skb from brdev %p\n", brdev);
165 if (brvcc->encaps == e_llc) {
166 + /* accept packets that have "ipv[46]" in the snap header */
167 + /* 8 - 2 == sizeof(llc_oui_ipv6) - BR2684_ETHERTYPE_LEN */
168 + if (memcmp(skb->data, llc_oui_ipv6, 8 - 2) == 0) {
169 + plen = sizeof(llc_oui_ipv6);
171 + if (memcmp(skb->data + 6, ethertype_ipv6, 2) == 0)
173 + __constant_htons(ETH_P_IPV6);
174 + else if (memcmp(skb->data + 6, ethertype_ipv4, 2)
176 + skb->protocol = __constant_htons(ETH_P_IP);
178 + brdev->stats.rx_errors++;
179 + dev_kfree_skb(skb);
182 + skb_pull(skb, plen);
183 + skb->nh.raw = skb->data;
184 + skb->pkt_type = PACKET_HOST;
187 /* let us waste some time for checking the encapsulation.
188 Note, that only 7 char is checked so frames with a valid FCS
189 are also accepted (but FCS is not checked of course) */
190 - if (memcmp(skb->data, llc_oui_pid_pad, 7)) {
191 + else if (memcmp(skb->data, llc_oui_pid_pad, 7) == 0) {
192 + skb_pull(skb, plen - ETH_HLEN);
194 + eth_type_trans(skb, &brdev->net_dev);
196 brdev->stats.rx_errors++;
201 - /* Strip FCS if present */
202 - if (skb->len > 7 && skb->data[7] == 0x01)
203 - __skb_trim(skb, skb->len - 4);
205 plen = PADLEN + ETH_HLEN; /* pad, dstmac,srcmac, ethtype */
206 /* first 2 chars should be 0 */
207 @@ -448,13 +548,14 @@
211 + skb_pull(skb, plen - ETH_HLEN);
212 + skb->protocol = eth_type_trans(skb, &brdev->net_dev);
214 if (skb->len < plen) {
215 brdev->stats.rx_errors++;
216 dev_kfree_skb(skb); /* dev_ not needed? */
220 #ifdef FASTER_VERSION
221 /* FIXME: tcpdump shows that pointer to mac header is 2 bytes earlier,
222 than should be. What else should I set? */
223 @@ -465,30 +566,29 @@
224 skb->protocol = ((u16 *) skb->data)[-1];
225 #else /* some protocols might require this: */
226 skb->protocol = br_type_trans(skb, &brdev->net_dev);
227 -#endif /* CONFIG_BR2684_FAST_TRANS */
228 +#endif /* CONFIG_BR2684_FAST_TRANS */
230 - skb_pull(skb, plen - ETH_HLEN);
231 - skb->protocol = eth_type_trans(skb, &brdev->net_dev);
232 -#endif /* FASTER_VERSION */
233 + /* skb_pull(skb, plen - ETH_HLEN); */
234 + /* skb->protocol = eth_type_trans(skb, &brdev->net_dev); */
235 +#endif /* FASTER_VERSION */
236 #ifdef CONFIG_ATM_BR2684_IPFILTER
237 if (packet_fails_filter(skb->protocol, brvcc, skb)) {
238 brdev->stats.rx_dropped++;
242 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
243 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
244 skb->dev = &brdev->net_dev;
245 - ATM_SKB(skb)->vcc = atmvcc; /* needed ? */
246 + /* ATM_SKB(skb)->vcc = atmvcc; *//* needed ? */
247 DPRINTK("received packet's protocol: %x\n", ntohs(skb->protocol));
249 - if (!(brdev->net_dev.flags & IFF_UP)) { /* sigh, interface is down */
250 + if (!(brdev->net_dev.flags & IFF_UP)) { /* sigh, interface is down */
251 brdev->stats.rx_dropped++;
255 brdev->stats.rx_packets++;
256 brdev->stats.rx_bytes += skb->len;
257 - memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
261 @@ -525,10 +625,10 @@
265 - if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO ||
266 - be.fcs_auto || be.has_vpiid || be.send_padding || (be.encaps !=
267 - BR2684_ENCAPS_VC && be.encaps != BR2684_ENCAPS_LLC) ||
268 - be.min_size != 0) {
269 + if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO
270 + || be.fcs_auto || be.has_vpiid || be.send_padding
271 + || (be.encaps != BR2684_ENCAPS_VC
272 + && be.encaps != BR2684_ENCAPS_LLC) || be.min_size != 0) {
276 @@ -554,18 +654,21 @@
277 brvcc->atmvcc = atmvcc;
278 atmvcc->user_back = brvcc;
279 brvcc->encaps = (enum br2684_encaps) be.encaps;
280 + brvcc->payload = (enum br2684_payload) be.payload;
281 brvcc->old_push = atmvcc->push;
283 atmvcc->push = br2684_push;
284 skb_queue_head_init(©);
285 skb_migrate(&atmvcc->sk->receive_queue, ©);
286 while ((skb = skb_dequeue(©))) {
288 BRPRIV(skb->dev)->stats.rx_bytes -= skb->len;
289 BRPRIV(skb->dev)->stats.rx_packets--;
291 br2684_push(atmvcc, skb);
296 write_unlock_irq(&devs_lock);
299 @@ -608,12 +711,25 @@
301 if (ni.ifname[0] != '\0') {
302 memcpy(brdev->net_dev.name, ni.ifname,
303 - sizeof(brdev->net_dev.name));
304 - brdev->net_dev.name[sizeof(brdev->net_dev.name) - 1] = '\0';
305 + sizeof(brdev->net_dev.name));
306 + brdev->net_dev.name[sizeof(brdev->net_dev.name) - 1] =
309 sprintf(brdev->net_dev.name, "nas%d", brdev->number);
310 DPRINTK("registered netdev %s\n", brdev->net_dev.name);
311 - ether_setup(&brdev->net_dev);
312 + if (ni.payload == p_routed) {
313 + brdev->net_dev.hard_header_len = 0;
314 + brdev->net_dev.addr_len = 0;
315 + brdev->net_dev.mtu = 1500;
317 + /* Type PPP seems most suitable */
318 + brdev->net_dev.type = ARPHRD_PPP;
319 + brdev->net_dev.flags =
320 + IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
321 + brdev->net_dev.tx_queue_len = 100;
323 + ether_setup(&brdev->net_dev);
325 brdev->mac_was_set = 0;
326 #ifdef FASTER_VERSION
327 my_eth_header = brdev->net_dev.hard_header;
328 @@ -677,12 +793,11 @@
329 err = br2684_setfilt(atmvcc, arg);
332 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
333 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
338 -#ifdef CONFIG_PROC_FS
339 /* Never put more than 256 bytes in at once */
340 static int br2684_proc_engine(loff_t pos, char *buf)
342 @@ -692,52 +807,62 @@
343 list_for_each(lhd, &br2684_devs) {
344 brdev = list_entry_brdev(lhd);
346 - return sprintf(buf, "dev %.16s: num=%d, mac=%02X:%02X:"
347 - "%02X:%02X:%02X:%02X (%s)\n", brdev->net_dev.name,
349 - brdev->net_dev.dev_addr[0],
350 - brdev->net_dev.dev_addr[1],
351 - brdev->net_dev.dev_addr[2],
352 - brdev->net_dev.dev_addr[3],
353 - brdev->net_dev.dev_addr[4],
354 - brdev->net_dev.dev_addr[5],
355 - brdev->mac_was_set ? "set" : "auto");
356 + return sprintf(buf,
357 + "dev %.16s: num=%d, mac=%02X:%02X:"
358 + "%02X:%02X:%02X:%02X (%s)\n",
359 + brdev->net_dev.name, brdev->number,
360 + brdev->net_dev.dev_addr[0],
361 + brdev->net_dev.dev_addr[1],
362 + brdev->net_dev.dev_addr[2],
363 + brdev->net_dev.dev_addr[3],
364 + brdev->net_dev.dev_addr[4],
365 + brdev->net_dev.dev_addr[5],
367 + mac_was_set ? "set" : "auto");
368 list_for_each(lhc, &brdev->brvccs) {
369 brvcc = list_entry_brvcc(lhc);
371 - return sprintf(buf, " vcc %d.%d.%d: encaps=%s"
372 + return sprintf(buf,
373 + " vcc %d.%d.%d: encaps=%s"
375 #ifndef FASTER_VERSION
376 - ", failed copies %u/%u"
377 -#endif /* FASTER_VERSION */
378 - "\n", brvcc->atmvcc->dev->number,
379 - brvcc->atmvcc->vpi, brvcc->atmvcc->vci,
380 - (brvcc->encaps == e_llc) ? "LLC" : "VC"
381 + ", failed copies %u/%u"
382 +#endif /* FASTER_VERSION */
384 + brvcc->atmvcc->dev->number,
385 + brvcc->atmvcc->vpi,
386 + brvcc->atmvcc->vci,
388 + e_llc) ? "LLC" : "VC",
390 + p_bridged) ? "bridged" :
392 #ifndef FASTER_VERSION
393 - , brvcc->copies_failed
394 - , brvcc->copies_needed
395 -#endif /* FASTER_VERSION */
396 + , brvcc->copies_failed,
397 + brvcc->copies_needed
398 +#endif /* FASTER_VERSION */
400 #ifdef CONFIG_ATM_BR2684_IPFILTER
401 #define b1(var, byte) ((u8 *) &brvcc->filter.var)[byte]
402 #define bs(var) b1(var, 0), b1(var, 1), b1(var, 2), b1(var, 3)
403 if (brvcc->filter.netmask != 0 && pos-- == 0)
404 - return sprintf(buf, " filter=%d.%d.%d.%d/"
405 - "%d.%d.%d.%d\n", bs(prefix), bs(netmask));
406 + return sprintf(buf,
407 + " filter=%d.%d.%d.%d/"
408 + "%d.%d.%d.%d\n", bs(prefix),
412 -#endif /* CONFIG_ATM_BR2684_IPFILTER */
413 +#endif /* CONFIG_ATM_BR2684_IPFILTER */
419 static ssize_t br2684_proc_read(struct file *file, char *buf, size_t count,
424 int len = 0, x, left;
427 page = get_free_page(GFP_KERNEL);
432 read_lock(&devs_lock);
434 - x = br2684_proc_engine(n, &((char *) page)[len]);
435 + x = br2684_proc_engine(*pos, &((char *) page)[len]);
439 @@ -761,12 +886,11 @@
448 read_unlock(&devs_lock);
450 if (len > 0 && copy_to_user(buf, (char *) page, len))
453 @@ -774,23 +898,20 @@
456 static struct file_operations br2684_proc_operations = {
457 - read: br2684_proc_read,
458 + read:br2684_proc_read,
461 extern struct proc_dir_entry *atm_proc_root; /* from proc.c */
462 -#endif /* CONFIG_PROC_FS */
464 /* the following avoids some spurious warnings from the compiler */
465 #define UNUSED __attribute__((unused))
467 static int __init UNUSED br2684_init(void)
469 -#ifdef CONFIG_PROC_FS
470 struct proc_dir_entry *p;
471 if ((p = create_proc_entry("br2684", 0, atm_proc_root)) == NULL)
473 p->proc_fops = &br2684_proc_operations;
474 -#endif /* CONFIG_PROC_FS */
475 br2684_ioctl_set(br2684_ioctl);
480 struct br2684_dev *brdev;
481 br2684_ioctl_set(NULL);
482 -#ifdef CONFIG_PROC_FS
483 remove_proc_entry("br2684", atm_proc_root);
484 -#endif /* CONFIG_PROC_FS */
485 while (!list_empty(&br2684_devs)) {
486 brdev = list_entry_brdev(br2684_devs.next);
487 unregister_netdev(&brdev->net_dev);
488 diff -urN linux-2.4.32/net/atm/common.c linux-2.4.32.new/net/atm/common.c
489 --- linux-2.4.32/net/atm/common.c 2004-02-18 14:36:32.000000000 +0100
490 +++ linux-2.4.32.new/net/atm/common.c 2006-02-06 17:26:52.000000000 +0100
493 #ifdef CONFIG_ATM_BR2684_MODULE
494 EXPORT_SYMBOL(br2684_ioctl_set);
495 +EXPORT_SYMBOL(br2684_ioctl_hook);
499 --- linux-2.4.32/include/linux/atmbr2684.h 2002-08-03 02:39:45.000000000 +0200
500 +++ linux-2.4.32.new/include/linux/atmbr2684.h 2006-02-06 19:01:24.000000000 +0100
503 #include <linux/atm.h>
504 #include <linux/if.h> /* For IFNAMSIZ */
505 +#include <linux/if_ether.h> /* ETH_P_* */
508 * Type of media we're bridging (ethernet, token ring, etc) Currently only
510 #define BR2684_ENCAPS_AUTODETECT (2) /* Unsuported */
513 + * Is this VC bridged or routed?
516 +#define BR2684_PAYLOAD_ROUTED (0)
517 +#define BR2684_PAYLOAD_BRIDGED (1)
521 * This is for the ATM_NEWBACKENDIF call - these are like socket families:
522 * the first element of the structure is the backend number and the rest
523 * is per-backend specific
525 struct atm_newif_br2684 {
526 - atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
527 - int media; /* BR2684_MEDIA_* */
528 - char ifname[IFNAMSIZ];
530 + atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
531 + int media; /* BR2684_MEDIA_* */
532 + char ifname[IFNAMSIZ];
534 + int payload; /* bridged or routed */
539 * is per-backend specific
541 struct atm_backend_br2684 {
542 - atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
543 + atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
544 struct br2684_if_spec ifspec;
545 - int fcs_in; /* BR2684_FCSIN_* */
546 - int fcs_out; /* BR2684_FCSOUT_* */
547 - int fcs_auto; /* 1: fcs_{in,out} disabled if no FCS rx'ed */
548 - int encaps; /* BR2684_ENCAPS_* */
549 - int has_vpiid; /* 1: use vpn_id - Unsupported */
551 - int send_padding; /* unsupported */
552 - int min_size; /* we will pad smaller packets than this */
553 + int fcs_in; /* BR2684_FCSIN_* */
554 + int fcs_out; /* BR2684_FCSOUT_* */
555 + int fcs_auto; /* 1: fcs_{in,out} disabled if no FCS rx'ed */
556 + int encaps; /* BR2684_ENCAPS_* */
557 + int payload; /* BR2684_PAYLOAD_* */
558 + int has_vpiid; /* 1: use vpn_id - Unsupported */
560 + int send_padding; /* unsupported */
561 + int min_size; /* we will pad smaller packets than this */
566 struct br2684_filter filter;
569 +enum br2684_payload {
570 + p_routed = BR2684_PAYLOAD_ROUTED,
571 + p_bridged = BR2684_PAYLOAD_BRIDGED,
574 #define BR2684_SETFILT _IOW( 'a', ATMIOC_BACKEND + 0, \
575 struct br2684_filter_set)
577 -#endif /* _LINUX_ATMBR2684_H */
578 +#endif /* _LINUX_ATMBR2684_H */