hdlc_fr.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /*
  2. * Generic HDLC support routines for Linux
  3. * Frame Relay support
  4. *
  5. * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License
  9. * as published by the Free Software Foundation.
  10. *
  11. Theory of PVC state
  12. DCE mode:
  13. (exist,new) -> 0,0 when "PVC create" or if "link unreliable"
  14. 0,x -> 1,1 if "link reliable" when sending FULL STATUS
  15. 1,1 -> 1,0 if received FULL STATUS ACK
  16. (active) -> 0 when "ifconfig PVC down" or "link unreliable" or "PVC create"
  17. -> 1 when "PVC up" and (exist,new) = 1,0
  18. DTE mode:
  19. (exist,new,active) = FULL STATUS if "link reliable"
  20. = 0, 0, 0 if "link unreliable"
  21. No LMI:
  22. active = open and "link reliable"
  23. exist = new = not used
  24. CCITT LMI: ITU-T Q.933 Annex A
  25. ANSI LMI: ANSI T1.617 Annex D
  26. CISCO LMI: the original, aka "Gang of Four" LMI
  27. */
  28. #include <linux/errno.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/hdlc.h>
  31. #include <linux/if_arp.h>
  32. #include <linux/inetdevice.h>
  33. #include <linux/init.h>
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/pkt_sched.h>
  37. #include <linux/poll.h>
  38. #include <linux/rtnetlink.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/slab.h>
  41. #undef DEBUG_PKT
  42. #undef DEBUG_ECN
  43. #undef DEBUG_LINK
  44. #undef DEBUG_PROTO
  45. #undef DEBUG_PVC
  46. #define FR_UI 0x03
  47. #define FR_PAD 0x00
  48. #define NLPID_IP 0xCC
  49. #define NLPID_IPV6 0x8E
  50. #define NLPID_SNAP 0x80
  51. #define NLPID_PAD 0x00
  52. #define NLPID_CCITT_ANSI_LMI 0x08
  53. #define NLPID_CISCO_LMI 0x09
  54. #define LMI_CCITT_ANSI_DLCI 0 /* LMI DLCI */
  55. #define LMI_CISCO_DLCI 1023
  56. #define LMI_CALLREF 0x00 /* Call Reference */
  57. #define LMI_ANSI_LOCKSHIFT 0x95 /* ANSI locking shift */
  58. #define LMI_ANSI_CISCO_REPTYPE 0x01 /* report type */
  59. #define LMI_CCITT_REPTYPE 0x51
  60. #define LMI_ANSI_CISCO_ALIVE 0x03 /* keep alive */
  61. #define LMI_CCITT_ALIVE 0x53
  62. #define LMI_ANSI_CISCO_PVCSTAT 0x07 /* PVC status */
  63. #define LMI_CCITT_PVCSTAT 0x57
  64. #define LMI_FULLREP 0x00 /* full report */
  65. #define LMI_INTEGRITY 0x01 /* link integrity report */
  66. #define LMI_SINGLE 0x02 /* single PVC report */
  67. #define LMI_STATUS_ENQUIRY 0x75
  68. #define LMI_STATUS 0x7D /* reply */
  69. #define LMI_REPT_LEN 1 /* report type element length */
  70. #define LMI_INTEG_LEN 2 /* link integrity element length */
  71. #define LMI_CCITT_CISCO_LENGTH 13 /* LMI frame lengths */
  72. #define LMI_ANSI_LENGTH 14
  73. struct fr_hdr {
  74. #if defined(__LITTLE_ENDIAN_BITFIELD)
  75. unsigned ea1: 1;
  76. unsigned cr: 1;
  77. unsigned dlcih: 6;
  78. unsigned ea2: 1;
  79. unsigned de: 1;
  80. unsigned becn: 1;
  81. unsigned fecn: 1;
  82. unsigned dlcil: 4;
  83. #else
  84. unsigned dlcih: 6;
  85. unsigned cr: 1;
  86. unsigned ea1: 1;
  87. unsigned dlcil: 4;
  88. unsigned fecn: 1;
  89. unsigned becn: 1;
  90. unsigned de: 1;
  91. unsigned ea2: 1;
  92. #endif
  93. } __packed;
  94. struct pvc_device {
  95. struct net_device *frad;
  96. struct net_device *main;
  97. struct net_device *ether; /* bridged Ethernet interface */
  98. struct pvc_device *next; /* Sorted in ascending DLCI order */
  99. int dlci;
  100. int open_count;
  101. struct {
  102. unsigned int new: 1;
  103. unsigned int active: 1;
  104. unsigned int exist: 1;
  105. unsigned int deleted: 1;
  106. unsigned int fecn: 1;
  107. unsigned int becn: 1;
  108. unsigned int bandwidth; /* Cisco LMI reporting only */
  109. }state;
  110. };
  111. struct frad_state {
  112. fr_proto settings;
  113. struct pvc_device *first_pvc;
  114. int dce_pvc_count;
  115. struct timer_list timer;
  116. struct net_device *dev;
  117. unsigned long last_poll;
  118. int reliable;
  119. int dce_changed;
  120. int request;
  121. int fullrep_sent;
  122. u32 last_errors; /* last errors bit list */
  123. u8 n391cnt;
  124. u8 txseq; /* TX sequence number */
  125. u8 rxseq; /* RX sequence number */
  126. };
  127. static int fr_ioctl(struct net_device *dev, struct ifreq *ifr);
  128. static inline u16 q922_to_dlci(u8 *hdr)
  129. {
  130. return ((hdr[0] & 0xFC) << 2) | ((hdr[1] & 0xF0) >> 4);
  131. }
  132. static inline void dlci_to_q922(u8 *hdr, u16 dlci)
  133. {
  134. hdr[0] = (dlci >> 2) & 0xFC;
  135. hdr[1] = ((dlci << 4) & 0xF0) | 0x01;
  136. }
  137. static inline struct frad_state* state(hdlc_device *hdlc)
  138. {
  139. return(struct frad_state *)(hdlc->state);
  140. }
  141. static inline struct pvc_device *find_pvc(hdlc_device *hdlc, u16 dlci)
  142. {
  143. struct pvc_device *pvc = state(hdlc)->first_pvc;
  144. while (pvc) {
  145. if (pvc->dlci == dlci)
  146. return pvc;
  147. if (pvc->dlci > dlci)
  148. return NULL; /* the list is sorted */
  149. pvc = pvc->next;
  150. }
  151. return NULL;
  152. }
  153. static struct pvc_device *add_pvc(struct net_device *dev, u16 dlci)
  154. {
  155. hdlc_device *hdlc = dev_to_hdlc(dev);
  156. struct pvc_device *pvc, **pvc_p = &state(hdlc)->first_pvc;
  157. while (*pvc_p) {
  158. if ((*pvc_p)->dlci == dlci)
  159. return *pvc_p;
  160. if ((*pvc_p)->dlci > dlci)
  161. break; /* the list is sorted */
  162. pvc_p = &(*pvc_p)->next;
  163. }
  164. pvc = kzalloc(sizeof(*pvc), GFP_ATOMIC);
  165. #ifdef DEBUG_PVC
  166. printk(KERN_DEBUG "add_pvc: allocated pvc %p, frad %p\n", pvc, dev);
  167. #endif
  168. if (!pvc)
  169. return NULL;
  170. pvc->dlci = dlci;
  171. pvc->frad = dev;
  172. pvc->next = *pvc_p; /* Put it in the chain */
  173. *pvc_p = pvc;
  174. return pvc;
  175. }
  176. static inline int pvc_is_used(struct pvc_device *pvc)
  177. {
  178. return pvc->main || pvc->ether;
  179. }
  180. static inline void pvc_carrier(int on, struct pvc_device *pvc)
  181. {
  182. if (on) {
  183. if (pvc->main)
  184. if (!netif_carrier_ok(pvc->main))
  185. netif_carrier_on(pvc->main);
  186. if (pvc->ether)
  187. if (!netif_carrier_ok(pvc->ether))
  188. netif_carrier_on(pvc->ether);
  189. } else {
  190. if (pvc->main)
  191. if (netif_carrier_ok(pvc->main))
  192. netif_carrier_off(pvc->main);
  193. if (pvc->ether)
  194. if (netif_carrier_ok(pvc->ether))
  195. netif_carrier_off(pvc->ether);
  196. }
  197. }
  198. static inline void delete_unused_pvcs(hdlc_device *hdlc)
  199. {
  200. struct pvc_device **pvc_p = &state(hdlc)->first_pvc;
  201. while (*pvc_p) {
  202. if (!pvc_is_used(*pvc_p)) {
  203. struct pvc_device *pvc = *pvc_p;
  204. #ifdef DEBUG_PVC
  205. printk(KERN_DEBUG "freeing unused pvc: %p\n", pvc);
  206. #endif
  207. *pvc_p = pvc->next;
  208. kfree(pvc);
  209. continue;
  210. }
  211. pvc_p = &(*pvc_p)->next;
  212. }
  213. }
  214. static inline struct net_device **get_dev_p(struct pvc_device *pvc,
  215. int type)
  216. {
  217. if (type == ARPHRD_ETHER)
  218. return &pvc->ether;
  219. else
  220. return &pvc->main;
  221. }
  222. static int fr_hard_header(struct sk_buff **skb_p, u16 dlci)
  223. {
  224. struct sk_buff *skb = *skb_p;
  225. if (!skb->dev) { /* Control packets */
  226. switch (dlci) {
  227. case LMI_CCITT_ANSI_DLCI:
  228. skb_push(skb, 4);
  229. skb->data[3] = NLPID_CCITT_ANSI_LMI;
  230. break;
  231. case LMI_CISCO_DLCI:
  232. skb_push(skb, 4);
  233. skb->data[3] = NLPID_CISCO_LMI;
  234. break;
  235. default:
  236. return -EINVAL;
  237. }
  238. } else if (skb->dev->type == ARPHRD_DLCI) {
  239. switch (skb->protocol) {
  240. case htons(ETH_P_IP):
  241. skb_push(skb, 4);
  242. skb->data[3] = NLPID_IP;
  243. break;
  244. case htons(ETH_P_IPV6):
  245. skb_push(skb, 4);
  246. skb->data[3] = NLPID_IPV6;
  247. break;
  248. default:
  249. skb_push(skb, 10);
  250. skb->data[3] = FR_PAD;
  251. skb->data[4] = NLPID_SNAP;
  252. /* OUI 00-00-00 indicates an Ethertype follows */
  253. skb->data[5] = 0x00;
  254. skb->data[6] = 0x00;
  255. skb->data[7] = 0x00;
  256. /* This should be an Ethertype: */
  257. *(__be16 *)(skb->data + 8) = skb->protocol;
  258. }
  259. } else if (skb->dev->type == ARPHRD_ETHER) {
  260. if (skb_headroom(skb) < 10) {
  261. struct sk_buff *skb2 = skb_realloc_headroom(skb, 10);
  262. if (!skb2)
  263. return -ENOBUFS;
  264. dev_kfree_skb(skb);
  265. skb = *skb_p = skb2;
  266. }
  267. skb_push(skb, 10);
  268. skb->data[3] = FR_PAD;
  269. skb->data[4] = NLPID_SNAP;
  270. /* OUI 00-80-C2 stands for the 802.1 organization */
  271. skb->data[5] = 0x00;
  272. skb->data[6] = 0x80;
  273. skb->data[7] = 0xC2;
  274. /* PID 00-07 stands for Ethernet frames without FCS */
  275. skb->data[8] = 0x00;
  276. skb->data[9] = 0x07;
  277. } else {
  278. return -EINVAL;
  279. }
  280. dlci_to_q922(skb->data, dlci);
  281. skb->data[2] = FR_UI;
  282. return 0;
  283. }
  284. static int pvc_open(struct net_device *dev)
  285. {
  286. struct pvc_device *pvc = dev->ml_priv;
  287. if ((pvc->frad->flags & IFF_UP) == 0)
  288. return -EIO; /* Frad must be UP in order to activate PVC */
  289. if (pvc->open_count++ == 0) {
  290. hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
  291. if (state(hdlc)->settings.lmi == LMI_NONE)
  292. pvc->state.active = netif_carrier_ok(pvc->frad);
  293. pvc_carrier(pvc->state.active, pvc);
  294. state(hdlc)->dce_changed = 1;
  295. }
  296. return 0;
  297. }
  298. static int pvc_close(struct net_device *dev)
  299. {
  300. struct pvc_device *pvc = dev->ml_priv;
  301. if (--pvc->open_count == 0) {
  302. hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
  303. if (state(hdlc)->settings.lmi == LMI_NONE)
  304. pvc->state.active = 0;
  305. if (state(hdlc)->settings.dce) {
  306. state(hdlc)->dce_changed = 1;
  307. pvc->state.active = 0;
  308. }
  309. }
  310. return 0;
  311. }
  312. static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  313. {
  314. struct pvc_device *pvc = dev->ml_priv;
  315. fr_proto_pvc_info info;
  316. if (ifr->ifr_settings.type == IF_GET_PROTO) {
  317. if (dev->type == ARPHRD_ETHER)
  318. ifr->ifr_settings.type = IF_PROTO_FR_ETH_PVC;
  319. else
  320. ifr->ifr_settings.type = IF_PROTO_FR_PVC;
  321. if (ifr->ifr_settings.size < sizeof(info)) {
  322. /* data size wanted */
  323. ifr->ifr_settings.size = sizeof(info);
  324. return -ENOBUFS;
  325. }
  326. info.dlci = pvc->dlci;
  327. memcpy(info.master, pvc->frad->name, IFNAMSIZ);
  328. if (copy_to_user(ifr->ifr_settings.ifs_ifsu.fr_pvc_info,
  329. &info, sizeof(info)))
  330. return -EFAULT;
  331. return 0;
  332. }
  333. return -EINVAL;
  334. }
  335. static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)
  336. {
  337. struct pvc_device *pvc = dev->ml_priv;
  338. if (pvc->state.active) {
  339. if (dev->type == ARPHRD_ETHER) {
  340. int pad = ETH_ZLEN - skb->len;
  341. if (pad > 0) { /* Pad the frame with zeros */
  342. int len = skb->len;
  343. if (skb_tailroom(skb) < pad)
  344. if (pskb_expand_head(skb, 0, pad,
  345. GFP_ATOMIC)) {
  346. dev->stats.tx_dropped++;
  347. dev_kfree_skb(skb);
  348. return NETDEV_TX_OK;
  349. }
  350. skb_put(skb, pad);
  351. memset(skb->data + len, 0, pad);
  352. }
  353. }
  354. skb->dev = dev;
  355. if (!fr_hard_header(&skb, pvc->dlci)) {
  356. dev->stats.tx_bytes += skb->len;
  357. dev->stats.tx_packets++;
  358. if (pvc->state.fecn) /* TX Congestion counter */
  359. dev->stats.tx_compressed++;
  360. skb->dev = pvc->frad;
  361. skb->protocol = htons(ETH_P_HDLC);
  362. skb_reset_network_header(skb);
  363. dev_queue_xmit(skb);
  364. return NETDEV_TX_OK;
  365. }
  366. }
  367. dev->stats.tx_dropped++;
  368. dev_kfree_skb(skb);
  369. return NETDEV_TX_OK;
  370. }
  371. static inline void fr_log_dlci_active(struct pvc_device *pvc)
  372. {
  373. netdev_info(pvc->frad, "DLCI %d [%s%s%s]%s %s\n",
  374. pvc->dlci,
  375. pvc->main ? pvc->main->name : "",
  376. pvc->main && pvc->ether ? " " : "",
  377. pvc->ether ? pvc->ether->name : "",
  378. pvc->state.new ? " new" : "",
  379. !pvc->state.exist ? "deleted" :
  380. pvc->state.active ? "active" : "inactive");
  381. }
  382. static inline u8 fr_lmi_nextseq(u8 x)
  383. {
  384. x++;
  385. return x ? x : 1;
  386. }
  387. static void fr_lmi_send(struct net_device *dev, int fullrep)
  388. {
  389. hdlc_device *hdlc = dev_to_hdlc(dev);
  390. struct sk_buff *skb;
  391. struct pvc_device *pvc = state(hdlc)->first_pvc;
  392. int lmi = state(hdlc)->settings.lmi;
  393. int dce = state(hdlc)->settings.dce;
  394. int len = lmi == LMI_ANSI ? LMI_ANSI_LENGTH : LMI_CCITT_CISCO_LENGTH;
  395. int stat_len = (lmi == LMI_CISCO) ? 6 : 3;
  396. u8 *data;
  397. int i = 0;
  398. if (dce && fullrep) {
  399. len += state(hdlc)->dce_pvc_count * (2 + stat_len);
  400. if (len > HDLC_MAX_MRU) {
  401. netdev_warn(dev, "Too many PVCs while sending LMI full report\n");
  402. return;
  403. }
  404. }
  405. skb = dev_alloc_skb(len);
  406. if (!skb) {
  407. netdev_warn(dev, "Memory squeeze on fr_lmi_send()\n");
  408. return;
  409. }
  410. memset(skb->data, 0, len);
  411. skb_reserve(skb, 4);
  412. if (lmi == LMI_CISCO) {
  413. fr_hard_header(&skb, LMI_CISCO_DLCI);
  414. } else {
  415. fr_hard_header(&skb, LMI_CCITT_ANSI_DLCI);
  416. }
  417. data = skb_tail_pointer(skb);
  418. data[i++] = LMI_CALLREF;
  419. data[i++] = dce ? LMI_STATUS : LMI_STATUS_ENQUIRY;
  420. if (lmi == LMI_ANSI)
  421. data[i++] = LMI_ANSI_LOCKSHIFT;
  422. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_REPTYPE :
  423. LMI_ANSI_CISCO_REPTYPE;
  424. data[i++] = LMI_REPT_LEN;
  425. data[i++] = fullrep ? LMI_FULLREP : LMI_INTEGRITY;
  426. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_ALIVE : LMI_ANSI_CISCO_ALIVE;
  427. data[i++] = LMI_INTEG_LEN;
  428. data[i++] = state(hdlc)->txseq =
  429. fr_lmi_nextseq(state(hdlc)->txseq);
  430. data[i++] = state(hdlc)->rxseq;
  431. if (dce && fullrep) {
  432. while (pvc) {
  433. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_PVCSTAT :
  434. LMI_ANSI_CISCO_PVCSTAT;
  435. data[i++] = stat_len;
  436. /* LMI start/restart */
  437. if (state(hdlc)->reliable && !pvc->state.exist) {
  438. pvc->state.exist = pvc->state.new = 1;
  439. fr_log_dlci_active(pvc);
  440. }
  441. /* ifconfig PVC up */
  442. if (pvc->open_count && !pvc->state.active &&
  443. pvc->state.exist && !pvc->state.new) {
  444. pvc_carrier(1, pvc);
  445. pvc->state.active = 1;
  446. fr_log_dlci_active(pvc);
  447. }
  448. if (lmi == LMI_CISCO) {
  449. data[i] = pvc->dlci >> 8;
  450. data[i + 1] = pvc->dlci & 0xFF;
  451. } else {
  452. data[i] = (pvc->dlci >> 4) & 0x3F;
  453. data[i + 1] = ((pvc->dlci << 3) & 0x78) | 0x80;
  454. data[i + 2] = 0x80;
  455. }
  456. if (pvc->state.new)
  457. data[i + 2] |= 0x08;
  458. else if (pvc->state.active)
  459. data[i + 2] |= 0x02;
  460. i += stat_len;
  461. pvc = pvc->next;
  462. }
  463. }
  464. skb_put(skb, i);
  465. skb->priority = TC_PRIO_CONTROL;
  466. skb->dev = dev;
  467. skb->protocol = htons(ETH_P_HDLC);
  468. skb_reset_network_header(skb);
  469. dev_queue_xmit(skb);
  470. }
  471. static void fr_set_link_state(int reliable, struct net_device *dev)
  472. {
  473. hdlc_device *hdlc = dev_to_hdlc(dev);
  474. struct pvc_device *pvc = state(hdlc)->first_pvc;
  475. state(hdlc)->reliable = reliable;
  476. if (reliable) {
  477. netif_dormant_off(dev);
  478. state(hdlc)->n391cnt = 0; /* Request full status */
  479. state(hdlc)->dce_changed = 1;
  480. if (state(hdlc)->settings.lmi == LMI_NONE) {
  481. while (pvc) { /* Activate all PVCs */
  482. pvc_carrier(1, pvc);
  483. pvc->state.exist = pvc->state.active = 1;
  484. pvc->state.new = 0;
  485. pvc = pvc->next;
  486. }
  487. }
  488. } else {
  489. netif_dormant_on(dev);
  490. while (pvc) { /* Deactivate all PVCs */
  491. pvc_carrier(0, pvc);
  492. pvc->state.exist = pvc->state.active = 0;
  493. pvc->state.new = 0;
  494. if (!state(hdlc)->settings.dce)
  495. pvc->state.bandwidth = 0;
  496. pvc = pvc->next;
  497. }
  498. }
  499. }
  500. static void fr_timer(struct timer_list *t)
  501. {
  502. struct frad_state *st = from_timer(st, t, timer);
  503. struct net_device *dev = st->dev;
  504. hdlc_device *hdlc = dev_to_hdlc(dev);
  505. int i, cnt = 0, reliable;
  506. u32 list;
  507. if (state(hdlc)->settings.dce) {
  508. reliable = state(hdlc)->request &&
  509. time_before(jiffies, state(hdlc)->last_poll +
  510. state(hdlc)->settings.t392 * HZ);
  511. state(hdlc)->request = 0;
  512. } else {
  513. state(hdlc)->last_errors <<= 1; /* Shift the list */
  514. if (state(hdlc)->request) {
  515. if (state(hdlc)->reliable)
  516. netdev_info(dev, "No LMI status reply received\n");
  517. state(hdlc)->last_errors |= 1;
  518. }
  519. list = state(hdlc)->last_errors;
  520. for (i = 0; i < state(hdlc)->settings.n393; i++, list >>= 1)
  521. cnt += (list & 1); /* errors count */
  522. reliable = (cnt < state(hdlc)->settings.n392);
  523. }
  524. if (state(hdlc)->reliable != reliable) {
  525. netdev_info(dev, "Link %sreliable\n", reliable ? "" : "un");
  526. fr_set_link_state(reliable, dev);
  527. }
  528. if (state(hdlc)->settings.dce)
  529. state(hdlc)->timer.expires = jiffies +
  530. state(hdlc)->settings.t392 * HZ;
  531. else {
  532. if (state(hdlc)->n391cnt)
  533. state(hdlc)->n391cnt--;
  534. fr_lmi_send(dev, state(hdlc)->n391cnt == 0);
  535. state(hdlc)->last_poll = jiffies;
  536. state(hdlc)->request = 1;
  537. state(hdlc)->timer.expires = jiffies +
  538. state(hdlc)->settings.t391 * HZ;
  539. }
  540. add_timer(&state(hdlc)->timer);
  541. }
  542. static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
  543. {
  544. hdlc_device *hdlc = dev_to_hdlc(dev);
  545. struct pvc_device *pvc;
  546. u8 rxseq, txseq;
  547. int lmi = state(hdlc)->settings.lmi;
  548. int dce = state(hdlc)->settings.dce;
  549. int stat_len = (lmi == LMI_CISCO) ? 6 : 3, reptype, error, no_ram, i;
  550. if (skb->len < (lmi == LMI_ANSI ? LMI_ANSI_LENGTH :
  551. LMI_CCITT_CISCO_LENGTH)) {
  552. netdev_info(dev, "Short LMI frame\n");
  553. return 1;
  554. }
  555. if (skb->data[3] != (lmi == LMI_CISCO ? NLPID_CISCO_LMI :
  556. NLPID_CCITT_ANSI_LMI)) {
  557. netdev_info(dev, "Received non-LMI frame with LMI DLCI\n");
  558. return 1;
  559. }
  560. if (skb->data[4] != LMI_CALLREF) {
  561. netdev_info(dev, "Invalid LMI Call reference (0x%02X)\n",
  562. skb->data[4]);
  563. return 1;
  564. }
  565. if (skb->data[5] != (dce ? LMI_STATUS_ENQUIRY : LMI_STATUS)) {
  566. netdev_info(dev, "Invalid LMI Message type (0x%02X)\n",
  567. skb->data[5]);
  568. return 1;
  569. }
  570. if (lmi == LMI_ANSI) {
  571. if (skb->data[6] != LMI_ANSI_LOCKSHIFT) {
  572. netdev_info(dev, "Not ANSI locking shift in LMI message (0x%02X)\n",
  573. skb->data[6]);
  574. return 1;
  575. }
  576. i = 7;
  577. } else
  578. i = 6;
  579. if (skb->data[i] != (lmi == LMI_CCITT ? LMI_CCITT_REPTYPE :
  580. LMI_ANSI_CISCO_REPTYPE)) {
  581. netdev_info(dev, "Not an LMI Report type IE (0x%02X)\n",
  582. skb->data[i]);
  583. return 1;
  584. }
  585. if (skb->data[++i] != LMI_REPT_LEN) {
  586. netdev_info(dev, "Invalid LMI Report type IE length (%u)\n",
  587. skb->data[i]);
  588. return 1;
  589. }
  590. reptype = skb->data[++i];
  591. if (reptype != LMI_INTEGRITY && reptype != LMI_FULLREP) {
  592. netdev_info(dev, "Unsupported LMI Report type (0x%02X)\n",
  593. reptype);
  594. return 1;
  595. }
  596. if (skb->data[++i] != (lmi == LMI_CCITT ? LMI_CCITT_ALIVE :
  597. LMI_ANSI_CISCO_ALIVE)) {
  598. netdev_info(dev, "Not an LMI Link integrity verification IE (0x%02X)\n",
  599. skb->data[i]);
  600. return 1;
  601. }
  602. if (skb->data[++i] != LMI_INTEG_LEN) {
  603. netdev_info(dev, "Invalid LMI Link integrity verification IE length (%u)\n",
  604. skb->data[i]);
  605. return 1;
  606. }
  607. i++;
  608. state(hdlc)->rxseq = skb->data[i++]; /* TX sequence from peer */
  609. rxseq = skb->data[i++]; /* Should confirm our sequence */
  610. txseq = state(hdlc)->txseq;
  611. if (dce)
  612. state(hdlc)->last_poll = jiffies;
  613. error = 0;
  614. if (!state(hdlc)->reliable)
  615. error = 1;
  616. if (rxseq == 0 || rxseq != txseq) { /* Ask for full report next time */
  617. state(hdlc)->n391cnt = 0;
  618. error = 1;
  619. }
  620. if (dce) {
  621. if (state(hdlc)->fullrep_sent && !error) {
  622. /* Stop sending full report - the last one has been confirmed by DTE */
  623. state(hdlc)->fullrep_sent = 0;
  624. pvc = state(hdlc)->first_pvc;
  625. while (pvc) {
  626. if (pvc->state.new) {
  627. pvc->state.new = 0;
  628. /* Tell DTE that new PVC is now active */
  629. state(hdlc)->dce_changed = 1;
  630. }
  631. pvc = pvc->next;
  632. }
  633. }
  634. if (state(hdlc)->dce_changed) {
  635. reptype = LMI_FULLREP;
  636. state(hdlc)->fullrep_sent = 1;
  637. state(hdlc)->dce_changed = 0;
  638. }
  639. state(hdlc)->request = 1; /* got request */
  640. fr_lmi_send(dev, reptype == LMI_FULLREP ? 1 : 0);
  641. return 0;
  642. }
  643. /* DTE */
  644. state(hdlc)->request = 0; /* got response, no request pending */
  645. if (error)
  646. return 0;
  647. if (reptype != LMI_FULLREP)
  648. return 0;
  649. pvc = state(hdlc)->first_pvc;
  650. while (pvc) {
  651. pvc->state.deleted = 1;
  652. pvc = pvc->next;
  653. }
  654. no_ram = 0;
  655. while (skb->len >= i + 2 + stat_len) {
  656. u16 dlci;
  657. u32 bw;
  658. unsigned int active, new;
  659. if (skb->data[i] != (lmi == LMI_CCITT ? LMI_CCITT_PVCSTAT :
  660. LMI_ANSI_CISCO_PVCSTAT)) {
  661. netdev_info(dev, "Not an LMI PVC status IE (0x%02X)\n",
  662. skb->data[i]);
  663. return 1;
  664. }
  665. if (skb->data[++i] != stat_len) {
  666. netdev_info(dev, "Invalid LMI PVC status IE length (%u)\n",
  667. skb->data[i]);
  668. return 1;
  669. }
  670. i++;
  671. new = !! (skb->data[i + 2] & 0x08);
  672. active = !! (skb->data[i + 2] & 0x02);
  673. if (lmi == LMI_CISCO) {
  674. dlci = (skb->data[i] << 8) | skb->data[i + 1];
  675. bw = (skb->data[i + 3] << 16) |
  676. (skb->data[i + 4] << 8) |
  677. (skb->data[i + 5]);
  678. } else {
  679. dlci = ((skb->data[i] & 0x3F) << 4) |
  680. ((skb->data[i + 1] & 0x78) >> 3);
  681. bw = 0;
  682. }
  683. pvc = add_pvc(dev, dlci);
  684. if (!pvc && !no_ram) {
  685. netdev_warn(dev, "Memory squeeze on fr_lmi_recv()\n");
  686. no_ram = 1;
  687. }
  688. if (pvc) {
  689. pvc->state.exist = 1;
  690. pvc->state.deleted = 0;
  691. if (active != pvc->state.active ||
  692. new != pvc->state.new ||
  693. bw != pvc->state.bandwidth ||
  694. !pvc->state.exist) {
  695. pvc->state.new = new;
  696. pvc->state.active = active;
  697. pvc->state.bandwidth = bw;
  698. pvc_carrier(active, pvc);
  699. fr_log_dlci_active(pvc);
  700. }
  701. }
  702. i += stat_len;
  703. }
  704. pvc = state(hdlc)->first_pvc;
  705. while (pvc) {
  706. if (pvc->state.deleted && pvc->state.exist) {
  707. pvc_carrier(0, pvc);
  708. pvc->state.active = pvc->state.new = 0;
  709. pvc->state.exist = 0;
  710. pvc->state.bandwidth = 0;
  711. fr_log_dlci_active(pvc);
  712. }
  713. pvc = pvc->next;
  714. }
  715. /* Next full report after N391 polls */
  716. state(hdlc)->n391cnt = state(hdlc)->settings.n391;
  717. return 0;
  718. }
  719. static int fr_rx(struct sk_buff *skb)
  720. {
  721. struct net_device *frad = skb->dev;
  722. hdlc_device *hdlc = dev_to_hdlc(frad);
  723. struct fr_hdr *fh = (struct fr_hdr *)skb->data;
  724. u8 *data = skb->data;
  725. u16 dlci;
  726. struct pvc_device *pvc;
  727. struct net_device *dev = NULL;
  728. if (skb->len <= 4 || fh->ea1 || data[2] != FR_UI)
  729. goto rx_error;
  730. dlci = q922_to_dlci(skb->data);
  731. if ((dlci == LMI_CCITT_ANSI_DLCI &&
  732. (state(hdlc)->settings.lmi == LMI_ANSI ||
  733. state(hdlc)->settings.lmi == LMI_CCITT)) ||
  734. (dlci == LMI_CISCO_DLCI &&
  735. state(hdlc)->settings.lmi == LMI_CISCO)) {
  736. if (fr_lmi_recv(frad, skb))
  737. goto rx_error;
  738. dev_kfree_skb_any(skb);
  739. return NET_RX_SUCCESS;
  740. }
  741. pvc = find_pvc(hdlc, dlci);
  742. if (!pvc) {
  743. #ifdef DEBUG_PKT
  744. netdev_info(frad, "No PVC for received frame's DLCI %d\n",
  745. dlci);
  746. #endif
  747. dev_kfree_skb_any(skb);
  748. return NET_RX_DROP;
  749. }
  750. if (pvc->state.fecn != fh->fecn) {
  751. #ifdef DEBUG_ECN
  752. printk(KERN_DEBUG "%s: DLCI %d FECN O%s\n", frad->name,
  753. dlci, fh->fecn ? "N" : "FF");
  754. #endif
  755. pvc->state.fecn ^= 1;
  756. }
  757. if (pvc->state.becn != fh->becn) {
  758. #ifdef DEBUG_ECN
  759. printk(KERN_DEBUG "%s: DLCI %d BECN O%s\n", frad->name,
  760. dlci, fh->becn ? "N" : "FF");
  761. #endif
  762. pvc->state.becn ^= 1;
  763. }
  764. if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
  765. frad->stats.rx_dropped++;
  766. return NET_RX_DROP;
  767. }
  768. if (data[3] == NLPID_IP) {
  769. skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */
  770. dev = pvc->main;
  771. skb->protocol = htons(ETH_P_IP);
  772. } else if (data[3] == NLPID_IPV6) {
  773. skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */
  774. dev = pvc->main;
  775. skb->protocol = htons(ETH_P_IPV6);
  776. } else if (skb->len > 10 && data[3] == FR_PAD &&
  777. data[4] == NLPID_SNAP && data[5] == FR_PAD) {
  778. u16 oui = ntohs(*(__be16*)(data + 6));
  779. u16 pid = ntohs(*(__be16*)(data + 8));
  780. skb_pull(skb, 10);
  781. switch ((((u32)oui) << 16) | pid) {
  782. case ETH_P_ARP: /* routed frame with SNAP */
  783. case ETH_P_IPX:
  784. case ETH_P_IP: /* a long variant */
  785. case ETH_P_IPV6:
  786. dev = pvc->main;
  787. skb->protocol = htons(pid);
  788. break;
  789. case 0x80C20007: /* bridged Ethernet frame */
  790. if ((dev = pvc->ether) != NULL)
  791. skb->protocol = eth_type_trans(skb, dev);
  792. break;
  793. default:
  794. netdev_info(frad, "Unsupported protocol, OUI=%x PID=%x\n",
  795. oui, pid);
  796. dev_kfree_skb_any(skb);
  797. return NET_RX_DROP;
  798. }
  799. } else {
  800. netdev_info(frad, "Unsupported protocol, NLPID=%x length=%i\n",
  801. data[3], skb->len);
  802. dev_kfree_skb_any(skb);
  803. return NET_RX_DROP;
  804. }
  805. if (dev) {
  806. dev->stats.rx_packets++; /* PVC traffic */
  807. dev->stats.rx_bytes += skb->len;
  808. if (pvc->state.becn)
  809. dev->stats.rx_compressed++;
  810. skb->dev = dev;
  811. netif_rx(skb);
  812. return NET_RX_SUCCESS;
  813. } else {
  814. dev_kfree_skb_any(skb);
  815. return NET_RX_DROP;
  816. }
  817. rx_error:
  818. frad->stats.rx_errors++; /* Mark error */
  819. dev_kfree_skb_any(skb);
  820. return NET_RX_DROP;
  821. }
  822. static void fr_start(struct net_device *dev)
  823. {
  824. hdlc_device *hdlc = dev_to_hdlc(dev);
  825. #ifdef DEBUG_LINK
  826. printk(KERN_DEBUG "fr_start\n");
  827. #endif
  828. if (state(hdlc)->settings.lmi != LMI_NONE) {
  829. state(hdlc)->reliable = 0;
  830. state(hdlc)->dce_changed = 1;
  831. state(hdlc)->request = 0;
  832. state(hdlc)->fullrep_sent = 0;
  833. state(hdlc)->last_errors = 0xFFFFFFFF;
  834. state(hdlc)->n391cnt = 0;
  835. state(hdlc)->txseq = state(hdlc)->rxseq = 0;
  836. state(hdlc)->dev = dev;
  837. timer_setup(&state(hdlc)->timer, fr_timer, 0);
  838. /* First poll after 1 s */
  839. state(hdlc)->timer.expires = jiffies + HZ;
  840. add_timer(&state(hdlc)->timer);
  841. } else
  842. fr_set_link_state(1, dev);
  843. }
  844. static void fr_stop(struct net_device *dev)
  845. {
  846. hdlc_device *hdlc = dev_to_hdlc(dev);
  847. #ifdef DEBUG_LINK
  848. printk(KERN_DEBUG "fr_stop\n");
  849. #endif
  850. if (state(hdlc)->settings.lmi != LMI_NONE)
  851. del_timer_sync(&state(hdlc)->timer);
  852. fr_set_link_state(0, dev);
  853. }
  854. static void fr_close(struct net_device *dev)
  855. {
  856. hdlc_device *hdlc = dev_to_hdlc(dev);
  857. struct pvc_device *pvc = state(hdlc)->first_pvc;
  858. while (pvc) { /* Shutdown all PVCs for this FRAD */
  859. if (pvc->main)
  860. dev_close(pvc->main);
  861. if (pvc->ether)
  862. dev_close(pvc->ether);
  863. pvc = pvc->next;
  864. }
  865. }
  866. static void pvc_setup(struct net_device *dev)
  867. {
  868. dev->type = ARPHRD_DLCI;
  869. dev->flags = IFF_POINTOPOINT;
  870. dev->hard_header_len = 0;
  871. dev->addr_len = 2;
  872. netif_keep_dst(dev);
  873. }
  874. static const struct net_device_ops pvc_ops = {
  875. .ndo_open = pvc_open,
  876. .ndo_stop = pvc_close,
  877. .ndo_start_xmit = pvc_xmit,
  878. .ndo_do_ioctl = pvc_ioctl,
  879. };
  880. static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
  881. {
  882. hdlc_device *hdlc = dev_to_hdlc(frad);
  883. struct pvc_device *pvc;
  884. struct net_device *dev;
  885. int used;
  886. if ((pvc = add_pvc(frad, dlci)) == NULL) {
  887. netdev_warn(frad, "Memory squeeze on fr_add_pvc()\n");
  888. return -ENOBUFS;
  889. }
  890. if (*get_dev_p(pvc, type))
  891. return -EEXIST;
  892. used = pvc_is_used(pvc);
  893. if (type == ARPHRD_ETHER)
  894. dev = alloc_netdev(0, "pvceth%d", NET_NAME_UNKNOWN,
  895. ether_setup);
  896. else
  897. dev = alloc_netdev(0, "pvc%d", NET_NAME_UNKNOWN, pvc_setup);
  898. if (!dev) {
  899. netdev_warn(frad, "Memory squeeze on fr_pvc()\n");
  900. delete_unused_pvcs(hdlc);
  901. return -ENOBUFS;
  902. }
  903. if (type == ARPHRD_ETHER) {
  904. dev->priv_flags &= ~IFF_TX_SKB_SHARING;
  905. eth_hw_addr_random(dev);
  906. } else {
  907. *(__be16*)dev->dev_addr = htons(dlci);
  908. dlci_to_q922(dev->broadcast, dlci);
  909. }
  910. dev->netdev_ops = &pvc_ops;
  911. dev->mtu = HDLC_MAX_MTU;
  912. dev->min_mtu = 68;
  913. dev->max_mtu = HDLC_MAX_MTU;
  914. dev->needed_headroom = 10;
  915. dev->priv_flags |= IFF_NO_QUEUE;
  916. dev->ml_priv = pvc;
  917. if (register_netdevice(dev) != 0) {
  918. free_netdev(dev);
  919. delete_unused_pvcs(hdlc);
  920. return -EIO;
  921. }
  922. dev->needs_free_netdev = true;
  923. *get_dev_p(pvc, type) = dev;
  924. if (!used) {
  925. state(hdlc)->dce_changed = 1;
  926. state(hdlc)->dce_pvc_count++;
  927. }
  928. return 0;
  929. }
  930. static int fr_del_pvc(hdlc_device *hdlc, unsigned int dlci, int type)
  931. {
  932. struct pvc_device *pvc;
  933. struct net_device *dev;
  934. if ((pvc = find_pvc(hdlc, dlci)) == NULL)
  935. return -ENOENT;
  936. if ((dev = *get_dev_p(pvc, type)) == NULL)
  937. return -ENOENT;
  938. if (dev->flags & IFF_UP)
  939. return -EBUSY; /* PVC in use */
  940. unregister_netdevice(dev); /* the destructor will free_netdev(dev) */
  941. *get_dev_p(pvc, type) = NULL;
  942. if (!pvc_is_used(pvc)) {
  943. state(hdlc)->dce_pvc_count--;
  944. state(hdlc)->dce_changed = 1;
  945. }
  946. delete_unused_pvcs(hdlc);
  947. return 0;
  948. }
  949. static void fr_destroy(struct net_device *frad)
  950. {
  951. hdlc_device *hdlc = dev_to_hdlc(frad);
  952. struct pvc_device *pvc = state(hdlc)->first_pvc;
  953. state(hdlc)->first_pvc = NULL; /* All PVCs destroyed */
  954. state(hdlc)->dce_pvc_count = 0;
  955. state(hdlc)->dce_changed = 1;
  956. while (pvc) {
  957. struct pvc_device *next = pvc->next;
  958. /* destructors will free_netdev() main and ether */
  959. if (pvc->main)
  960. unregister_netdevice(pvc->main);
  961. if (pvc->ether)
  962. unregister_netdevice(pvc->ether);
  963. kfree(pvc);
  964. pvc = next;
  965. }
  966. }
  967. static struct hdlc_proto proto = {
  968. .close = fr_close,
  969. .start = fr_start,
  970. .stop = fr_stop,
  971. .detach = fr_destroy,
  972. .ioctl = fr_ioctl,
  973. .netif_rx = fr_rx,
  974. .module = THIS_MODULE,
  975. };
  976. static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
  977. {
  978. fr_proto __user *fr_s = ifr->ifr_settings.ifs_ifsu.fr;
  979. const size_t size = sizeof(fr_proto);
  980. fr_proto new_settings;
  981. hdlc_device *hdlc = dev_to_hdlc(dev);
  982. fr_proto_pvc pvc;
  983. int result;
  984. switch (ifr->ifr_settings.type) {
  985. case IF_GET_PROTO:
  986. if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
  987. return -EINVAL;
  988. ifr->ifr_settings.type = IF_PROTO_FR;
  989. if (ifr->ifr_settings.size < size) {
  990. ifr->ifr_settings.size = size; /* data size wanted */
  991. return -ENOBUFS;
  992. }
  993. if (copy_to_user(fr_s, &state(hdlc)->settings, size))
  994. return -EFAULT;
  995. return 0;
  996. case IF_PROTO_FR:
  997. if (!capable(CAP_NET_ADMIN))
  998. return -EPERM;
  999. if (dev->flags & IFF_UP)
  1000. return -EBUSY;
  1001. if (copy_from_user(&new_settings, fr_s, size))
  1002. return -EFAULT;
  1003. if (new_settings.lmi == LMI_DEFAULT)
  1004. new_settings.lmi = LMI_ANSI;
  1005. if ((new_settings.lmi != LMI_NONE &&
  1006. new_settings.lmi != LMI_ANSI &&
  1007. new_settings.lmi != LMI_CCITT &&
  1008. new_settings.lmi != LMI_CISCO) ||
  1009. new_settings.t391 < 1 ||
  1010. new_settings.t392 < 2 ||
  1011. new_settings.n391 < 1 ||
  1012. new_settings.n392 < 1 ||
  1013. new_settings.n393 < new_settings.n392 ||
  1014. new_settings.n393 > 32 ||
  1015. (new_settings.dce != 0 &&
  1016. new_settings.dce != 1))
  1017. return -EINVAL;
  1018. result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT);
  1019. if (result)
  1020. return result;
  1021. if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */
  1022. result = attach_hdlc_protocol(dev, &proto,
  1023. sizeof(struct frad_state));
  1024. if (result)
  1025. return result;
  1026. state(hdlc)->first_pvc = NULL;
  1027. state(hdlc)->dce_pvc_count = 0;
  1028. }
  1029. memcpy(&state(hdlc)->settings, &new_settings, size);
  1030. dev->type = ARPHRD_FRAD;
  1031. call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
  1032. return 0;
  1033. case IF_PROTO_FR_ADD_PVC:
  1034. case IF_PROTO_FR_DEL_PVC:
  1035. case IF_PROTO_FR_ADD_ETH_PVC:
  1036. case IF_PROTO_FR_DEL_ETH_PVC:
  1037. if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
  1038. return -EINVAL;
  1039. if (!capable(CAP_NET_ADMIN))
  1040. return -EPERM;
  1041. if (copy_from_user(&pvc, ifr->ifr_settings.ifs_ifsu.fr_pvc,
  1042. sizeof(fr_proto_pvc)))
  1043. return -EFAULT;
  1044. if (pvc.dlci <= 0 || pvc.dlci >= 1024)
  1045. return -EINVAL; /* Only 10 bits, DLCI 0 reserved */
  1046. if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC ||
  1047. ifr->ifr_settings.type == IF_PROTO_FR_DEL_ETH_PVC)
  1048. result = ARPHRD_ETHER; /* bridged Ethernet device */
  1049. else
  1050. result = ARPHRD_DLCI;
  1051. if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_PVC ||
  1052. ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC)
  1053. return fr_add_pvc(dev, pvc.dlci, result);
  1054. else
  1055. return fr_del_pvc(hdlc, pvc.dlci, result);
  1056. }
  1057. return -EINVAL;
  1058. }
  1059. static int __init mod_init(void)
  1060. {
  1061. register_hdlc_protocol(&proto);
  1062. return 0;
  1063. }
  1064. static void __exit mod_exit(void)
  1065. {
  1066. unregister_hdlc_protocol(&proto);
  1067. }
  1068. module_init(mod_init);
  1069. module_exit(mod_exit);
  1070. MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
  1071. MODULE_DESCRIPTION("Frame-Relay protocol support for generic HDLC");
  1072. MODULE_LICENSE("GPL v2");