/* * Ethernet netdevice using ATM AAL5 as underlying carrier * (RFC1483 obsoleted by RFC2684) for Linux * * Authors: Marcell GAL, 2000, XDSL Ltd, Hungary * Eric Kinzie, 2006-2007, US Naval Research Laboratory */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "common.h" /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ #if defined(CONFIG_MACH_FUSIV) static unsigned char atmMacAddr[6] = {0x0,0x0,0x1,0x0,0x0,0x0}; // =========================================================================== // Function name: ATM_getPermanentMacAddress // Input Parameters: none // Output Parameters: mac address // Result: none // Description: Returns the mac address to be used for all ATM based // logical interfaces. // =========================================================================== void ATM_getPermanentMacAddress_local(unsigned char *macAddr) { memcpy(macAddr, atmMacAddr, 6); } //extern int AtmUpdateNewVCInfo(int encap, struct atm_vcc *atmvcc, int moduleId,char *ifname); int (*AtmUpdateNewVCInfo_ptr)(int encap, struct atm_vcc *atmvcc, int moduleId, char *ifname) = NULL; int (*AtmUpdateVCInfo_ptr)(void *atmqos) = NULL; //extern int AtmDeleteVCInfo(short vpi,int vci); int (*AtmDeleteVCInfo_ptr)(short vpi,int vci) =NULL; //extern void ATM_getPermanentMacAddress(unsigned char *macAddr); #define ADI_BR2684_MODULE 2 struct atm_vcc * adi_getvcc(char *ifname); #define LLC_BRIDGED_OVERHEAD 10 #define VC_BRIDGED_OVERHEAD 2 #define LLC_ROUTED_OVERHEAD 8 #define VC_ROUTED_OVERHEAD 0 #endif #if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) int (*br2684AddMacAddrToAP_ptr)(unsigned char* dev_addr) = NULL; int (*br2684DelMacAddrFromAP_ptr)(unsigned char* dev_addr) = NULL; #endif #ifdef SKB_DEBUG static void skb_debug(const struct sk_buff *skb) { #define NUM2PRINT 50 char buf[NUM2PRINT * 3 + 1]; /* 3 chars per byte */ int i = 0; for (i = 0; i < skb->len && i < NUM2PRINT; i++) { sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]); } printk(KERN_DEBUG "br2684: skb: %s\n", buf); } #else #define skb_debug(skb) do {} while (0) #endif int (*getConfigModuleId_ptr)(int vpi,int vci) = NULL; #if defined(CONFIG_FUSIV_KERNEL_PPPOE_RELAY) || defined(CONFIG_FUSIV_KERNEL_PPPOE_RELAY_MODULE) int (*checkPPPOERelayStatus_ptr)(char *name) = NULL; #endif #define BR2684_ETHERTYPE_LEN 2 #define BR2684_PAD_LEN 2 #define LLC 0xaa, 0xaa, 0x03 #define SNAP_BRIDGED 0x00, 0x80, 0xc2 #define SNAP_ROUTED 0x00, 0x00, 0x00 #define PID_ETHERNET 0x00, 0x07 #define ETHERTYPE_IPV4 0x08, 0x00 #define ETHERTYPE_IPV6 0x86, 0xdd #define PAD_BRIDGED 0x00, 0x00 static const unsigned char ethertype_ipv4[] = { ETHERTYPE_IPV4 }; static const unsigned char ethertype_ipv6[] = { ETHERTYPE_IPV6 }; static const unsigned char llc_oui_pid_pad[] = { LLC, SNAP_BRIDGED, PID_ETHERNET, PAD_BRIDGED }; static const unsigned char llc_oui_ipv4[] = { LLC, SNAP_ROUTED, ETHERTYPE_IPV4 }; static const unsigned char llc_oui_ipv6[] = { LLC, SNAP_ROUTED, ETHERTYPE_IPV6 }; enum br2684_encaps { e_vc = BR2684_ENCAPS_VC, e_llc = BR2684_ENCAPS_LLC, }; struct br2684_vcc { struct atm_vcc *atmvcc; struct net_device *device; /* keep old push, pop functions for chaining */ void (*old_push) (struct atm_vcc * vcc, struct sk_buff * skb); /* void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb); */ enum br2684_encaps encaps; struct list_head brvccs; #ifdef CONFIG_ATM_BR2684_IPFILTER struct br2684_filter filter; #endif /* CONFIG_ATM_BR2684_IPFILTER */ unsigned copies_needed, copies_failed; }; static void br2684_close_vcc(struct br2684_vcc *brvcc); struct br2684_dev { struct net_device *net_dev; struct list_head br2684_devs; int number; struct list_head brvccs; /* one device <=> one vcc (before xmas) */ struct net_device_stats stats; int mac_was_set; enum br2684_payload payload; }; /* * This lock should be held for writing any time the list of devices or * their attached vcc's could be altered. It should be held for reading * any time these are being queried. Note that we sometimes need to * do read-locking under interrupt context, so write locking must block * the current CPU's interrupts */ static DEFINE_RWLOCK(devs_lock); static LIST_HEAD(br2684_devs); static inline struct br2684_dev *BRPRIV(const struct net_device *net_dev) { return (struct br2684_dev *)net_dev->priv; } static inline struct net_device *list_entry_brdev(const struct list_head *le) { return list_entry(le, struct br2684_dev, br2684_devs)->net_dev; } static inline struct br2684_vcc *BR2684_VCC(const struct atm_vcc *atmvcc) { return (struct br2684_vcc *)(atmvcc->user_back); } static inline struct br2684_vcc *list_entry_brvcc(const struct list_head *le) { return list_entry(le, struct br2684_vcc, brvccs); } /* Caller should hold read_lock(&devs_lock) */ static struct net_device *br2684_find_dev(const struct br2684_if_spec *s) { struct list_head *lh; struct net_device *net_dev; switch (s->method) { case BR2684_FIND_BYNUM: list_for_each(lh, &br2684_devs) { net_dev = list_entry_brdev(lh); if (BRPRIV(net_dev)->number == s->spec.devnum) return net_dev; } break; case BR2684_FIND_BYIFNAME: list_for_each(lh, &br2684_devs) { net_dev = list_entry_brdev(lh); if (!strncmp(net_dev->name, s->spec.ifname, IFNAMSIZ)) return net_dev; } break; } return NULL; } /* * Send a packet out a particular vcc. Not to useful right now, but paves * the way for multiple vcc's per itf. Returns true if we can send, * otherwise false */ static int br2684_xmit_vcc(struct sk_buff *skb, struct br2684_dev *brdev, struct br2684_vcc *brvcc) { struct atm_vcc *atmvcc; int minheadroom = (brvcc->encaps == e_llc) ? 10 : 2; if (skb_headroom(skb) < minheadroom) { struct sk_buff *skb2 = skb_realloc_headroom(skb, minheadroom); brvcc->copies_needed++; dev_kfree_skb(skb); if (skb2 == NULL) { brvcc->copies_failed++; return 0; } skb = skb2; } if (brvcc->encaps == e_llc) { if (brdev->payload == p_bridged) { skb_push(skb, sizeof(llc_oui_pid_pad)); skb_copy_to_linear_data(skb, llc_oui_pid_pad, sizeof(llc_oui_pid_pad)); } else if (brdev->payload == p_routed) { unsigned short prot = ntohs(skb->protocol); skb_push(skb, sizeof(llc_oui_ipv4)); switch (prot) { case ETH_P_IP: skb_copy_to_linear_data(skb, llc_oui_ipv4, sizeof(llc_oui_ipv4)); break; case ETH_P_IPV6: skb_copy_to_linear_data(skb, llc_oui_ipv6, sizeof(llc_oui_ipv6)); break; default: dev_kfree_skb(skb); return 0; } } } else { /* e_vc */ if (brdev->payload == p_bridged) { skb_push(skb, 2); memset(skb->data, 0, 2); } else { /* p_routed */ skb_pull(skb, ETH_HLEN); } } skb_debug(skb); ATM_SKB(skb)->vcc = atmvcc = brvcc->atmvcc; pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->dev); if (!atm_may_send(atmvcc, skb->truesize)) { /* * We free this here for now, because we cannot know in a higher * layer whether the skb pointer it supplied wasn't freed yet. * Now, it always is. */ dev_kfree_skb(skb); return 0; } #if !defined(CONFIG_MACH_FUSIV) atomic_add(skb->truesize, &sk_atm(atmvcc)->sk_wmem_alloc); #endif ATM_SKB(skb)->atm_options = atmvcc->atm_options; brdev->stats.tx_packets++; brdev->stats.tx_bytes += skb->len; atmvcc->send(atmvcc, skb); return 1; } static inline struct br2684_vcc *pick_outgoing_vcc(const struct sk_buff *skb, const struct br2684_dev *brdev) { return list_empty(&brdev->brvccs) ? NULL : list_entry_brvcc(brdev->brvccs.next); /* 1 vcc/dev right now */ } static int br2684_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct br2684_dev *brdev = BRPRIV(dev); struct br2684_vcc *brvcc; pr_debug("br2684_start_xmit, skb->dst=%p\n", skb->dst); read_lock(&devs_lock); brvcc = pick_outgoing_vcc(skb, brdev); if (brvcc == NULL) { pr_debug("no vcc attached to dev %s\n", dev->name); brdev->stats.tx_errors++; brdev->stats.tx_carrier_errors++; /* netif_stop_queue(dev); */ dev_kfree_skb(skb); read_unlock(&devs_lock); return 0; } if (!br2684_xmit_vcc(skb, brdev, brvcc)) { /* * We should probably use netif_*_queue() here, but that * involves added complication. We need to walk before * we can run. * * Don't free here! this pointer might be no longer valid! */ brdev->stats.tx_errors++; brdev->stats.tx_fifo_errors++; } read_unlock(&devs_lock); return 0; } static struct net_device_stats *br2684_get_stats(struct net_device *dev) { pr_debug("br2684_get_stats\n"); return &BRPRIV(dev)->stats; } /* * We remember when the MAC gets set, so we don't override it later with * the ESI of the ATM card of the first VC */ static int (*my_eth_mac_addr) (struct net_device *, void *); static int br2684_mac_addr(struct net_device *dev, void *p) { int err = 0; unsigned char old_mac[6]; memcpy(old_mac , dev->dev_addr , 6); err = my_eth_mac_addr(dev, p); if (!err) { BRPRIV(dev)->mac_was_set = 1; #if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) // delete the old mac in AP and add new one if (br2684DelMacAddrFromAP_ptr) br2684DelMacAddrFromAP_ptr(old_mac); if (br2684AddMacAddrToAP_ptr) br2684AddMacAddrToAP_ptr(dev->dev_addr); #endif } return err; } #ifdef CONFIG_ATM_BR2684_IPFILTER /* this IOCTL is experimental. */ static int br2684_setfilt(struct atm_vcc *atmvcc, void __user * arg) { struct br2684_vcc *brvcc; struct br2684_filter_set fs; if (copy_from_user(&fs, arg, sizeof fs)) return -EFAULT; if (fs.ifspec.method != BR2684_FIND_BYNOTHING) { /* * This is really a per-vcc thing, but we can also search * by device. */ struct br2684_dev *brdev; read_lock(&devs_lock); brdev = BRPRIV(br2684_find_dev(&fs.ifspec)); if (brdev == NULL || list_empty(&brdev->brvccs) || brdev->brvccs.next != brdev->brvccs.prev) /* >1 VCC */ brvcc = NULL; else brvcc = list_entry_brvcc(brdev->brvccs.next); read_unlock(&devs_lock); if (brvcc == NULL) return -ESRCH; } else brvcc = BR2684_VCC(atmvcc); memcpy(&brvcc->filter, &fs.filter, sizeof(brvcc->filter)); return 0; } /* Returns 1 if packet should be dropped */ static inline int packet_fails_filter(__be16 type, struct br2684_vcc *brvcc, struct sk_buff *skb) { if (brvcc->filter.netmask == 0) return 0; /* no filter in place */ if (type == htons(ETH_P_IP) && (((struct iphdr *)(skb->data))->daddr & brvcc->filter. netmask) == brvcc->filter.prefix) return 0; if (type == htons(ETH_P_ARP)) return 0; /* * TODO: we should probably filter ARPs too.. don't want to have * them returning values that don't make sense, or is that ok? */ return 1; /* drop */ } #endif /* CONFIG_ATM_BR2684_IPFILTER */ static void br2684_close_vcc(struct br2684_vcc *brvcc) { pr_debug("removing VCC %p from dev %p\n", brvcc, brvcc->device); write_lock_irq(&devs_lock); list_del(&brvcc->brvccs); write_unlock_irq(&devs_lock); brvcc->atmvcc->user_back = NULL; /* what about vcc->recvq ??? */ brvcc->old_push(brvcc->atmvcc, NULL); /* pass on the bad news */ kfree(brvcc); module_put(THIS_MODULE); } /* when AAL5 PDU comes in: */ static void br2684_push(struct atm_vcc *atmvcc, struct sk_buff *skb) { struct br2684_vcc *brvcc = BR2684_VCC(atmvcc); int plen = sizeof(llc_oui_pid_pad) + ETH_HLEN; #if !defined(CONFIG_MACH_FUSIV) struct net_device *net_dev = brvcc->device; struct br2684_dev *brdev = BRPRIV(net_dev); #else struct net_device *net_dev = NULL; struct br2684_dev *brdev = NULL; if (brvcc) { net_dev = brvcc->device; if (net_dev) brdev = BRPRIV(net_dev); else return; } else return; #endif pr_debug("br2684_push\n"); if (unlikely(skb == NULL)) { /* skb==NULL means VCC is being destroyed */ br2684_close_vcc(brvcc); if (list_empty(&brdev->brvccs)) { write_lock_irq(&devs_lock); list_del(&brdev->br2684_devs); write_unlock_irq(&devs_lock); #if defined(CONFIG_MACH_FUSIV) #if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) if (br2684DelMacAddrFromAP_ptr) { br2684DelMacAddrFromAP_ptr(net_dev->dev_addr); } #endif #endif unregister_netdev(net_dev); free_netdev(net_dev); } #if defined(CONFIG_MACH_FUSIV) if(AtmDeleteVCInfo_ptr != NULL) (*AtmDeleteVCInfo_ptr)(atmvcc->vpi, atmvcc->vci); else printk("\nbr2684: atmdriver_lkm not initialized properly...\n"); #endif return; } skb_debug(skb); atm_return(atmvcc, skb->truesize); pr_debug("skb from brdev %p\n", brdev); if (brvcc->encaps == e_llc) { #if !defined(CONFIG_MACH_FUSIV) if (skb->len > 7 && skb->data[7] == 0x01) __skb_trim(skb, skb->len - 4); /* accept packets that have "ipv[46]" in the snap header */ if ((skb->len >= (sizeof(llc_oui_ipv4))) && (memcmp (skb->data, llc_oui_ipv4, sizeof(llc_oui_ipv4) - BR2684_ETHERTYPE_LEN) == 0)) { if (memcmp (skb->data + 6, ethertype_ipv6, sizeof(ethertype_ipv6)) == 0) skb->protocol = htons(ETH_P_IPV6); else if (memcmp (skb->data + 6, ethertype_ipv4, sizeof(ethertype_ipv4)) == 0) skb->protocol = htons(ETH_P_IP); else goto error; skb_pull(skb, sizeof(llc_oui_ipv4)); skb_reset_network_header(skb); skb->pkt_type = PACKET_HOST; /* * Let us waste some time for checking the encapsulation. * Note, that only 7 char is checked so frames with a valid FCS * are also accepted (but FCS is not checked of course). */ } else if ((skb->len >= sizeof(llc_oui_pid_pad)) && (memcmp(skb->data, llc_oui_pid_pad, 7) == 0)) { skb_pull(skb, sizeof(llc_oui_pid_pad)); skb->protocol = eth_type_trans(skb, net_dev); } else goto error; #else skb->pkt_type = PACKET_HOST; skb->protocol = eth_type_trans(skb, net_dev); #endif } else { /* e_vc */ #if !defined(CONFIG_MACH_FUSIV) if (brdev->payload == p_routed) { struct iphdr *iph; skb_reset_network_header(skb); iph = ip_hdr(skb); if (iph->version == 4) skb->protocol = htons(ETH_P_IP); else if (iph->version == 6) skb->protocol = htons(ETH_P_IPV6); else goto error; skb->pkt_type = PACKET_HOST; } else { /* p_bridged */ /* first 2 chars should be 0 */ if (*((u16 *) (skb->data)) != 0) goto error; skb_pull(skb, BR2684_PAD_LEN); skb->protocol = eth_type_trans(skb, net_dev); } #else skb->pkt_type = PACKET_HOST; skb->protocol = eth_type_trans(skb, net_dev); #endif } #ifdef CONFIG_ATM_BR2684_IPFILTER if (unlikely(packet_fails_filter(skb->protocol, brvcc, skb))) goto dropped; #endif /* CONFIG_ATM_BR2684_IPFILTER */ skb->dev = net_dev; ATM_SKB(skb)->vcc = atmvcc; /* needed ? */ pr_debug("received packet's protocol: %x\n", ntohs(skb->protocol)); skb_debug(skb); /* sigh, interface is down? */ if (unlikely(!(net_dev->flags & IFF_UP))) goto dropped; brdev->stats.rx_packets++; brdev->stats.rx_bytes += skb->len; memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data)); netif_rx(skb); return; dropped: brdev->stats.rx_dropped++; goto free_skb; error: brdev->stats.rx_errors++; free_skb: dev_kfree_skb(skb); return; } #if defined(CONFIG_IFX_PPA_A6) || defined(CONFIG_IFX_PPA_A5) || defined(CONFIG_IFX_PPA_A4) extern void (*ppa_hook_mpoa_setup)(struct atm_vcc *, int, int); #endif #if defined(CONFIG_MACH_FUSIV) static int br2684_delete(struct atm_vcc *atmvcc, void __user *arg) { int err,modId; struct br2684_vcc *brvcc; struct sk_buff_head copy; struct sk_buff *skb; struct br2684_dev *brdev; struct net_device *net_dev; struct atm_backend_br2684 be; if (copy_from_user(&be, arg, sizeof be)) { return -EFAULT; } atmvcc = adi_getvcc (be.ifspec.spec.ifname); if (!atmvcc) { printk(" ATM VCC not configured \n"); return -EFAULT; } #if defined(CONFIG_FUSIV_KERNEL_PPPOE_RELAY) || defined(CONFIG_FUSIV_KERNEL_PPPOE_RELAY_MODULE) if(getConfigModuleId_ptr == NULL || checkPPPOERelayStatus_ptr == NULL) { printk("\nbr2684: pppoerelay module not get initialized properly...\n"); return -1; } if ( (modId = (*getConfigModuleId_ptr)(atmvcc->vpi,atmvcc->vci)) != -1) { if ( modId == 5) { if( ((*checkPPPOERelayStatus_ptr)(be.ifspec.spec.ifname)) ) { printk("Device %s is Busy.Disable PPPOE Relay and Delete %s interface from Relay\n",be.ifspec.spec.ifname,be.ifspec.spec.ifname); return -EFAULT; } } } #endif #if defined(CONFIG_MACH_FUSIV) if(AtmDeleteVCInfo_ptr != NULL) { (*AtmDeleteVCInfo_ptr)(atmvcc->vpi, atmvcc->vci); } else printk("\nbr2684: atmdriver_lkm not initialized properly...\n"); // AtmDeleteVCInfo(atmvcc->vpi, atmvcc->vci); #endif brvcc = BR2684_VCC(atmvcc); net_dev = brvcc->device; brdev = BRPRIV(net_dev); br2684_close_vcc(brvcc); if (list_empty(&brdev->brvccs)) { read_lock(&devs_lock); list_del(&brdev->br2684_devs); read_unlock(&devs_lock); #if defined(CONFIG_MACH_FUSIV) #if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) if (br2684DelMacAddrFromAP_ptr) { br2684DelMacAddrFromAP_ptr(net_dev->dev_addr); } #endif #endif unregister_netdev(net_dev); free_netdev(net_dev); } clear_bit(ATM_VF_READY, &atmvcc->flags); clear_bit(ATM_VF_ADDR, &atmvcc->flags); return 0; } #endif /* * Assign a vcc to a dev * Note: we do not have explicit unassign, but look at _push() */ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg) { int err; struct br2684_vcc *brvcc; struct sk_buff *skb; struct sk_buff_head *rq; struct br2684_dev *brdev; struct net_device *net_dev; struct atm_backend_br2684 be; unsigned long flags; if (copy_from_user(&be, arg, sizeof be)) return -EFAULT; brvcc = kzalloc(sizeof(struct br2684_vcc), GFP_KERNEL); if (!brvcc) return -ENOMEM; write_lock_irq(&devs_lock); net_dev = br2684_find_dev(&be.ifspec); if (net_dev == NULL) { printk(KERN_ERR "br2684: tried to attach to non-existant device\n"); err = -ENXIO; goto error; } brdev = BRPRIV(net_dev); if (atmvcc->push == NULL) { err = -EBADFD; goto error; } if (!list_empty(&brdev->brvccs)) { /* Only 1 VCC/dev right now */ err = -EEXIST; goto error; } if (be.fcs_in != BR2684_FCSIN_NO || be.fcs_out != BR2684_FCSOUT_NO || be.fcs_auto || be.has_vpiid || be.send_padding || (be.encaps != BR2684_ENCAPS_VC && be.encaps != BR2684_ENCAPS_LLC) || be.min_size != 0) { err = -EINVAL; goto error; } pr_debug("br2684_regvcc vcc=%p, encaps=%d, brvcc=%p\n", atmvcc, be.encaps, brvcc); if (list_empty(&brdev->brvccs) && !brdev->mac_was_set) { unsigned char *esi = atmvcc->dev->esi; #if defined(CONFIG_MACH_FUSIV) atmvcc->dev->esi[5] = 0x1+brdev->number; esi = atmvcc->dev->esi; #endif if (esi[0] | esi[1] | esi[2] | esi[3] | esi[4] | esi[5]) memcpy(net_dev->dev_addr, esi, net_dev->addr_len); else net_dev->dev_addr[2] = 1; } list_add(&brvcc->brvccs, &brdev->brvccs); write_unlock_irq(&devs_lock); brvcc->device = net_dev; brvcc->atmvcc = atmvcc; atmvcc->user_back = brvcc; brvcc->encaps = (enum br2684_encaps)be.encaps; brvcc->old_push = atmvcc->push; barrier(); atmvcc->push = br2684_push; #if defined(CONFIG_IFX_PPA_A6) || defined(CONFIG_IFX_PPA_A5) || defined(CONFIG_IFX_PPA_A4) if ( ppa_hook_mpoa_setup ) ppa_hook_mpoa_setup(atmvcc, brdev->payload == p_routed ? 3 : 0, brvcc->encaps == BR2684_ENCAPS_LLC ? 1 : 0); // IPoA or EoA w/o FCS #endif rq = &sk_atm(atmvcc)->sk_receive_queue; spin_lock_irqsave(&rq->lock, flags); if (skb_queue_empty(rq)) { skb = NULL; } else { /* NULL terminate the list. */ rq->prev->next = NULL; skb = rq->next; } rq->prev = rq->next = (struct sk_buff *)rq; rq->qlen = 0; spin_unlock_irqrestore(&rq->lock, flags); while (skb) { struct sk_buff *next = skb->next; skb->next = skb->prev = NULL; br2684_push(atmvcc, skb); BRPRIV(skb->dev)->stats.rx_bytes -= skb->len; BRPRIV(skb->dev)->stats.rx_packets--; skb = next; } __module_get(THIS_MODULE); #if defined(CONFIG_MACH_FUSIV) if(AtmUpdateNewVCInfo_ptr != NULL) { if((err =(*AtmUpdateNewVCInfo_ptr)(be.encaps, atmvcc, ADI_BR2684_MODULE, brdev->net_dev->name)) < 0) { return err; } #if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) if (br2684AddMacAddrToAP_ptr) { err = br2684AddMacAddrToAP_ptr( net_dev->dev_addr); if (err < 0) return err; } else { printk("\nbr2684AddMacToAP: Atmdriver_lkm not initialized properly\n"); } #endif } else printk("\nbr2684: Atmdriver_lkm not initialized properly\n"); #endif return 0; error: write_unlock_irq(&devs_lock); kfree(brvcc); return err; } static void br2684_setup(struct net_device *netdev) { struct br2684_dev *brdev = BRPRIV(netdev); ether_setup(netdev); brdev->net_dev = netdev; my_eth_mac_addr = netdev->set_mac_address; netdev->set_mac_address = br2684_mac_addr; netdev->hard_start_xmit = br2684_start_xmit; netdev->get_stats = br2684_get_stats; INIT_LIST_HEAD(&brdev->brvccs); } static void br2684_setup_routed(struct net_device *netdev) { struct br2684_dev *brdev = BRPRIV(netdev); brdev->net_dev = netdev; netdev->hard_header_len = 0; my_eth_mac_addr = netdev->set_mac_address; netdev->set_mac_address = br2684_mac_addr; netdev->hard_start_xmit = br2684_start_xmit; netdev->get_stats = br2684_get_stats; netdev->addr_len = 0; netdev->mtu = 1500; netdev->type = ARPHRD_PPP; netdev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; netdev->tx_queue_len = 100; INIT_LIST_HEAD(&brdev->brvccs); } static int br2684_create(void __user * arg) { int err; struct net_device *netdev; struct br2684_dev *brdev; struct atm_newif_br2684 ni; enum br2684_payload payload; pr_debug("br2684_create\n"); if (copy_from_user(&ni, arg, sizeof ni)) { return -EFAULT; } if (ni.media & BR2684_FLAG_ROUTED) payload = p_routed; else payload = p_bridged; ni.media &= 0xffff; /* strip flags */ if (ni.media != BR2684_MEDIA_ETHERNET || ni.mtu != 1500) { return -EINVAL; } netdev = alloc_netdev(sizeof(struct br2684_dev), ni.ifname[0] ? ni.ifname : "nas%d", (payload == p_routed) ? br2684_setup_routed : br2684_setup); if (!netdev) return -ENOMEM; brdev = BRPRIV(netdev); pr_debug("registered netdev %s\n", netdev->name); /* open, stop, do_ioctl ? */ err = register_netdev(netdev); if (err < 0) { printk(KERN_ERR "br2684_create: register_netdev failed\n"); free_netdev(netdev); return err; } write_lock_irq(&devs_lock); brdev->payload = payload; brdev->number = list_empty(&br2684_devs) ? 1 : BRPRIV(list_entry_brdev(br2684_devs.prev))->number + 1; list_add_tail(&brdev->br2684_devs, &br2684_devs); write_unlock_irq(&devs_lock); return 0; } /* * This handles ioctls actually performed on our vcc - we must return * -ENOIOCTLCMD for any unrecognized ioctl */ static int br2684_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) { struct atm_vcc *atmvcc = ATM_SD(sock); void __user *argp = (void __user *)arg; atm_backend_t b; int err; switch (cmd) { case ATM_SETBACKEND: case ATM_NEWBACKENDIF: err = get_user(b, (atm_backend_t __user *) argp); if (err) return -EFAULT; if (b != ATM_BACKEND_BR2684) return -ENOIOCTLCMD; if (!capable(CAP_NET_ADMIN)) return -EPERM; if (cmd == ATM_SETBACKEND) return br2684_regvcc(atmvcc, argp); else return br2684_create(argp); #ifdef CONFIG_ATM_BR2684_IPFILTER case BR2684_SETFILT: if (atmvcc->push != br2684_push) return -ENOIOCTLCMD; if (!capable(CAP_NET_ADMIN)) return -EPERM; err = br2684_setfilt(atmvcc, argp); return err; #endif /* CONFIG_ATM_BR2684_IPFILTER */ #if defined(CONFIG_MACH_FUSIV) case ATM_DEL_INTERFACE: { atm_backend_t b; err = get_user(b, (atm_backend_t __user *) argp); if (err) return -EFAULT; br2684_delete(atmvcc, argp); } return 0; #endif } return -ENOIOCTLCMD; } static struct atm_ioctl br2684_ioctl_ops = { .owner = THIS_MODULE, .ioctl = br2684_ioctl, }; #ifdef CONFIG_PROC_FS static void *br2684_seq_start(struct seq_file *seq, loff_t * pos) __acquires(devs_lock) { read_lock(&devs_lock); return seq_list_start(&br2684_devs, *pos); } static void *br2684_seq_next(struct seq_file *seq, void *v, loff_t * pos) { return seq_list_next(v, &br2684_devs, pos); } static void br2684_seq_stop(struct seq_file *seq, void *v) __releases(devs_lock) { read_unlock(&devs_lock); } static int br2684_seq_show(struct seq_file *seq, void *v) { const struct br2684_dev *brdev = list_entry(v, struct br2684_dev, br2684_devs); const struct net_device *net_dev = brdev->net_dev; const struct br2684_vcc *brvcc; DECLARE_MAC_BUF(mac); seq_printf(seq, "dev %.16s: num=%d, mac=%s (%s)\n", net_dev->name, brdev->number, print_mac(mac, net_dev->dev_addr), brdev->mac_was_set ? "set" : "auto"); list_for_each_entry(brvcc, &brdev->brvccs, brvccs) { seq_printf(seq, " vcc %d.%d.%d: encaps=%s payload=%s" ", failed copies %u/%u" "\n", brvcc->atmvcc->dev->number, brvcc->atmvcc->vpi, brvcc->atmvcc->vci, (brvcc->encaps == e_llc) ? "LLC" : "VC", (brdev->payload == p_bridged) ? "bridged" : "routed", brvcc->copies_failed, brvcc->copies_needed); #ifdef CONFIG_ATM_BR2684_IPFILTER #define b1(var, byte) ((u8 *) &brvcc->filter.var)[byte] #define bs(var) b1(var, 0), b1(var, 1), b1(var, 2), b1(var, 3) if (brvcc->filter.netmask != 0) seq_printf(seq, " filter=%d.%d.%d.%d/" "%d.%d.%d.%d\n", bs(prefix), bs(netmask)); #undef bs #undef b1 #endif /* CONFIG_ATM_BR2684_IPFILTER */ } return 0; } static const struct seq_operations br2684_seq_ops = { .start = br2684_seq_start, .next = br2684_seq_next, .stop = br2684_seq_stop, .show = br2684_seq_show, }; static int br2684_proc_open(struct inode *inode, struct file *file) { return seq_open(file, &br2684_seq_ops); } static const struct file_operations br2684_proc_ops = { .owner = THIS_MODULE, .open = br2684_proc_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, }; extern struct proc_dir_entry *atm_proc_root; /* from proc.c */ #endif /* CONFIG_PROC_FS */ static int __init br2684_init(void) { #ifdef CONFIG_PROC_FS struct proc_dir_entry *p; p = proc_create("br2684", 0, atm_proc_root, &br2684_proc_ops); if (p == NULL) return -ENOMEM; #endif register_atm_ioctl(&br2684_ioctl_ops); return 0; } static void __exit br2684_exit(void) { struct net_device *net_dev; struct br2684_dev *brdev; struct br2684_vcc *brvcc; deregister_atm_ioctl(&br2684_ioctl_ops); #ifdef CONFIG_PROC_FS remove_proc_entry("br2684", atm_proc_root); #endif while (!list_empty(&br2684_devs)) { net_dev = list_entry_brdev(br2684_devs.next); brdev = BRPRIV(net_dev); while (!list_empty(&brdev->brvccs)) { brvcc = list_entry_brvcc(brdev->brvccs.next); br2684_close_vcc(brvcc); } list_del(&brdev->br2684_devs); unregister_netdev(net_dev); free_netdev(net_dev); } } #if defined(CONFIG_MACH_FUSIV) /* Just temporary -need to modify a lot */ struct atm_vcc * adi_getvcc(char *ifname) { struct list_head *lh; struct br2684_dev *brdev; struct br2684_vcc *br_vcc; struct net_device *net_dev; list_for_each(lh, &br2684_devs) { net_dev = list_entry_brdev(lh); if (strcmp(net_dev->name, ifname) == 0 ) { brdev = BRPRIV(net_dev); br_vcc = list_entry_brvcc(brdev->brvccs.next); return br_vcc->atmvcc; } } return NULL; } int get_br2684_encap(struct atm_vcc *atmvcc) { struct br2684_vcc *brvcc = BR2684_VCC(atmvcc); if(brvcc->encaps == e_llc ) return 1; else return 0; } int get_br2684_overhead(struct net_device *net_dev) { struct br2684_dev *brdev = NULL; struct br2684_vcc *brvcc = NULL; brdev = BRPRIV(net_dev); if(brdev == NULL) return 0; else { brvcc = list_entry_brvcc(brdev->brvccs.next); if(brvcc == NULL) return 0; } if(brdev->payload == BR2684_PAYLOAD_BRIDGED) { if (brvcc->encaps == e_llc) return LLC_BRIDGED_OVERHEAD; else return VC_BRIDGED_OVERHEAD; } else { if (brvcc->encaps == e_llc) return LLC_ROUTED_OVERHEAD; else return VC_ROUTED_OVERHEAD; } } struct net_device* get_br2684_ifname(struct atm_vcc *atmvcc) { struct br2684_vcc *brvcc = BR2684_VCC(atmvcc); if (!brvcc) return NULL; /* Error checks before returning to l2Datareceived routine. Return NULL if device is not valid or if the device status is not 'UP */ if(!brvcc->device) return NULL; if(!(brvcc->device->flags & IFF_UP)) return NULL; return brvcc->device; } EXPORT_SYMBOL(adi_getvcc); EXPORT_SYMBOL(get_br2684_encap); EXPORT_SYMBOL(get_br2684_overhead); EXPORT_SYMBOL(get_br2684_ifname); #endif module_init(br2684_init); module_exit(br2684_exit); #if defined(CONFIG_MACH_FUSIV) EXPORT_SYMBOL(AtmUpdateNewVCInfo_ptr); EXPORT_SYMBOL(AtmUpdateVCInfo_ptr); EXPORT_SYMBOL(AtmDeleteVCInfo_ptr); #if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) EXPORT_SYMBOL(br2684AddMacAddrToAP_ptr); EXPORT_SYMBOL(br2684DelMacAddrFromAP_ptr); #endif #endif EXPORT_SYMBOL(getConfigModuleId_ptr); #if defined(CONFIG_FUSIV_KERNEL_PPPOE_RELAY) || defined(CONFIG_FUSIV_KERNEL_PPPOE_RELAY_MODULE) EXPORT_SYMBOL(checkPPPOERelayStatus_ptr); #endif #if defined(CONFIG_IFX_PPA_API) || defined(CONFIG_IFX_PPA_API_MODULE) int ppa_br2684_get_vcc(struct net_device *netif, struct atm_vcc **pvcc) { if ( netif && (uint32_t)br2684_start_xmit == (uint32_t)netif->hard_start_xmit ) { struct br2684_dev *brdev; struct br2684_vcc *brvcc; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) brdev = (struct br2684_dev *)netif->priv; #else brdev = (struct br2684_dev *)((char *)(netif) - (unsigned long)(&((struct br2684_dev *)0)->net_dev)); #endif brvcc = list_empty(&brdev->brvccs) ? NULL : list_entry(brdev->brvccs.next, struct br2684_vcc, brvccs); if ( brvcc ) { *pvcc = brvcc->atmvcc; return 0; } } return -1; } int32_t ppa_if_is_br2684(struct net_device *netif, char *ifname) { if ( !netif ) { netif = dev_get_by_name(ifname); if ( !netif ) return 0; // can not get else dev_put(netif); } return (uint32_t)br2684_start_xmit == (uint32_t)netif->hard_start_xmit ? 1 : 0; } int32_t ppa_if_is_ipoa(struct net_device *netif, char *ifname) { if ( !netif ) { netif = dev_get_by_name(ifname); if ( !netif ) return 0; else dev_put(netif); } if ( ppa_if_is_br2684(netif, ifname) ) { struct br2684_dev *brdev; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) //brdev = (struct br2684_dev *)netif->priv; brdev = BRPRIV(netif); #else brdev = (struct br2684_dev *)((char *)(netif) - (unsigned long)(&((struct br2684_dev *)0)->net_dev)); #endif return brdev && brdev->payload == p_routed ? 1 : 0; } return 0; } #endif MODULE_AUTHOR("Marcell GAL"); MODULE_DESCRIPTION("RFC2684 bridged protocols over ATM/AAL5"); MODULE_LICENSE("GPL"); #if defined(CONFIG_IFX_PPA_API_MODULE) EXPORT_SYMBOL(ppa_if_is_ipoa); EXPORT_SYMBOL(ppa_if_is_br2684); EXPORT_SYMBOL(ppa_br2684_get_vcc); #endif