···11/*22 * Generic HDLC support routines for Linux33 *44- * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>44+ * Copyright (C) 1999 - 2008 Krzysztof Halasa <khc@pm.waw.pl>55 *66 * This program is free software; you can redistribute it and/or modify it77 * under the terms of version 2 of the GNU General Public License···3939#include <net/net_namespace.h>404041414242-static const char* version = "HDLC support module revision 1.21";4242+static const char* version = "HDLC support module revision 1.22";43434444#undef DEBUG_LINK4545···6666static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,6767 struct packet_type *p, struct net_device *orig_dev)6868{6969- struct hdlc_device_desc *desc = dev_to_desc(dev);6969+ struct hdlc_device *hdlc = dev_to_hdlc(dev);70707171 if (dev->nd_net != &init_net) {7272 kfree_skb(skb);7373 return 0;7474 }75757676- if (desc->netif_rx)7777- return desc->netif_rx(skb);7878-7979- desc->stats.rx_dropped++; /* Shouldn't happen */8080- dev_kfree_skb(skb);8181- return NET_RX_DROP;7676+ BUG_ON(!hdlc->proto->netif_rx);7777+ return hdlc->proto->netif_rx(skb);8278}83798480···8387{8488 hdlc_device *hdlc = dev_to_hdlc(dev);8589 if (hdlc->proto->start)8686- return hdlc->proto->start(dev);9090+ hdlc->proto->start(dev);8791}88928993···9296{9397 hdlc_device *hdlc = dev_to_hdlc(dev);9498 if (hdlc->proto->stop)9595- return hdlc->proto->stop(dev);9999+ hdlc->proto->stop(dev);96100}9710198102···259263struct net_device *alloc_hdlcdev(void *priv)260264{261265 struct net_device *dev;262262- dev = alloc_netdev(sizeof(struct hdlc_device_desc) +263263- sizeof(hdlc_device), "hdlc%d", hdlc_setup);266266+ dev = alloc_netdev(sizeof(struct hdlc_device), "hdlc%d", hdlc_setup);264267 if (dev)265268 dev_to_hdlc(dev)->priv = priv;266269 return dev;···276281277282278283int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,279279- int (*rx)(struct sk_buff *skb), size_t size)284284+ size_t size)280285{281286 detach_hdlc_protocol(dev);282287···292297 return -ENOBUFS;293298 }294299 dev_to_hdlc(dev)->proto = proto;295295- dev_to_desc(dev)->netif_rx = rx;296300 return 0;297301}298302
+3-2
drivers/net/wan/hdlc_cisco.c
···250250 return NET_RX_DROP;251251252252 rx_error:253253- dev_to_desc(dev)->stats.rx_errors++; /* Mark error */253253+ dev_to_hdlc(dev)->stats.rx_errors++; /* Mark error */254254 dev_kfree_skb_any(skb);255255 return NET_RX_DROP;256256}···314314 .stop = cisco_stop,315315 .type_trans = cisco_type_trans,316316 .ioctl = cisco_ioctl,317317+ .netif_rx = cisco_rx,317318 .module = THIS_MODULE,318319};319320···361360 if (result)362361 return result;363362364364- result = attach_hdlc_protocol(dev, &proto, cisco_rx,363363+ result = attach_hdlc_protocol(dev, &proto,365364 sizeof(struct cisco_state));366365 if (result)367366 return result;
+4-3
drivers/net/wan/hdlc_fr.c
···956956957957958958 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {959959- dev_to_desc(frad)->stats.rx_dropped++;959959+ dev_to_hdlc(frad)->stats.rx_dropped++;960960 return NET_RX_DROP;961961 }962962···10171017 }1018101810191019 rx_error:10201020- dev_to_desc(frad)->stats.rx_errors++; /* Mark error */10201020+ dev_to_hdlc(frad)->stats.rx_errors++; /* Mark error */10211021 dev_kfree_skb_any(skb);10221022 return NET_RX_DROP;10231023}···12171217 .stop = fr_stop,12181218 .detach = fr_destroy,12191219 .ioctl = fr_ioctl,12201220+ .netif_rx = fr_rx,12201221 .module = THIS_MODULE,12211222};12221223···12761275 return result;1277127612781277 if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */12791279- result = attach_hdlc_protocol(dev, &proto, fr_rx,12781278+ result = attach_hdlc_protocol(dev, &proto,12801279 sizeof(struct frad_state));12811280 if (result)12821281 return result;
+1-1
drivers/net/wan/hdlc_ppp.c
···122122 if (result)123123 return result;124124125125- result = attach_hdlc_protocol(dev, &proto, NULL,125125+ result = attach_hdlc_protocol(dev, &proto,126126 sizeof(struct ppp_state));127127 if (result)128128 return result;
+1-1
drivers/net/wan/hdlc_raw.c
···8282 if (result)8383 return result;84848585- result = attach_hdlc_protocol(dev, &proto, NULL,8585+ result = attach_hdlc_protocol(dev, &proto,8686 sizeof(raw_hdlc_proto));8787 if (result)8888 return result;
+1-1
drivers/net/wan/hdlc_raw_eth.c
···9696 if (result)9797 return result;98989999- result = attach_hdlc_protocol(dev, &proto, NULL,9999+ result = attach_hdlc_protocol(dev, &proto,100100 sizeof(raw_hdlc_proto));101101 if (result)102102 return result;
···2626#include <linux/netdevice.h>2727#include <linux/hdlc/ioctl.h>28282929-3030-/* Used by all network devices here, pointed to by netdev_priv(dev) */3131-struct hdlc_device_desc {3232- int (*netif_rx)(struct sk_buff *skb);3333- struct net_device_stats stats;3434-};3535-3629/* This structure is a private property of HDLC protocols.3730 Hardware drivers have no interest here */3831···3744 void (*detach)(struct net_device *dev);3845 int (*ioctl)(struct net_device *dev, struct ifreq *ifr);3946 __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);4747+ int (*netif_rx)(struct sk_buff *skb);4048 struct module *module;4149 struct hdlc_proto *next; /* next protocol in the list */4250};435144525353+/* Pointed to by dev->priv */4554typedef struct hdlc_device {5555+ struct net_device_stats stats;4656 /* used by HDLC layer to take control over HDLC device from hw driver*/4757 int (*attach)(struct net_device *dev,4858 unsigned short encoding, unsigned short parity);···79838084struct net_device *alloc_hdlcdev(void *priv);81858282-8383-static __inline__ struct hdlc_device_desc* dev_to_desc(struct net_device *dev)8686+static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)8487{8585- return netdev_priv(dev);8888+ return dev->priv;8689}8787-8888-static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev)8989-{9090- return netdev_priv(dev) + sizeof(struct hdlc_device_desc);9191-}9292-93909491static __inline__ void debug_frame(const struct sk_buff *skb)9592{···105116void hdlc_close(struct net_device *dev);106117107118int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,108108- int (*rx)(struct sk_buff *skb), size_t size);119119+ size_t size);109120/* May be used by hardware driver to gain control over HDLC device */110121void detach_hdlc_protocol(struct net_device *dev);111122112123static __inline__ struct net_device_stats *hdlc_stats(struct net_device *dev)113124{114114- return &dev_to_desc(dev)->stats;125125+ return &dev_to_hdlc(dev)->stats;115126}116127117128