hdlc_fr.c 29 KB

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