hdlc_fr.c 30 KB

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