hdlc_fr.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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. }__attribute__ ((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 listed 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 __constant_htons(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 __constant_htons(NLPID_CISCO_LMI):
  231. head_len = 4;
  232. skb_push(skb, head_len);
  233. skb->data[3] = NLPID_CISCO_LMI;
  234. break;
  235. case __constant_htons(ETH_P_IP):
  236. head_len = 4;
  237. skb_push(skb, head_len);
  238. skb->data[3] = NLPID_IP;
  239. break;
  240. case __constant_htons(ETH_P_IPV6):
  241. head_len = 4;
  242. skb_push(skb, head_len);
  243. skb->data[3] = NLPID_IPV6;
  244. break;
  245. case __constant_htons(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->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->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->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 int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
  330. {
  331. pvc_device *pvc = dev->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 0;
  343. }
  344. skb_put(skb, pad);
  345. memset(skb->data + len, 0, pad);
  346. }
  347. skb->protocol = __constant_htons(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 0;
  357. }
  358. }
  359. dev->stats.tx_dropped++;
  360. dev_kfree_skb(skb);
  361. return 0;
  362. }
  363. static int pvc_change_mtu(struct net_device *dev, int new_mtu)
  364. {
  365. if ((new_mtu < 68) || (new_mtu > HDLC_MAX_MTU))
  366. return -EINVAL;
  367. dev->mtu = new_mtu;
  368. return 0;
  369. }
  370. static inline void fr_log_dlci_active(pvc_device *pvc)
  371. {
  372. printk(KERN_INFO "%s: DLCI %d [%s%s%s]%s %s\n",
  373. pvc->frad->name,
  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. 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. printk(KERN_WARNING "%s: Too many PVCs while sending "
  402. "LMI full report\n", dev->name);
  403. return;
  404. }
  405. }
  406. skb = dev_alloc_skb(len);
  407. if (!skb) {
  408. printk(KERN_WARNING "%s: Memory squeeze on fr_lmi_send()\n",
  409. dev->name);
  410. return;
  411. }
  412. memset(skb->data, 0, len);
  413. skb_reserve(skb, 4);
  414. if (lmi == LMI_CISCO) {
  415. skb->protocol = __constant_htons(NLPID_CISCO_LMI);
  416. fr_hard_header(&skb, LMI_CISCO_DLCI);
  417. } else {
  418. skb->protocol = __constant_htons(NLPID_CCITT_ANSI_LMI);
  419. fr_hard_header(&skb, LMI_CCITT_ANSI_DLCI);
  420. }
  421. data = skb_tail_pointer(skb);
  422. data[i++] = LMI_CALLREF;
  423. data[i++] = dce ? LMI_STATUS : LMI_STATUS_ENQUIRY;
  424. if (lmi == LMI_ANSI)
  425. data[i++] = LMI_ANSI_LOCKSHIFT;
  426. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_REPTYPE :
  427. LMI_ANSI_CISCO_REPTYPE;
  428. data[i++] = LMI_REPT_LEN;
  429. data[i++] = fullrep ? LMI_FULLREP : LMI_INTEGRITY;
  430. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_ALIVE : LMI_ANSI_CISCO_ALIVE;
  431. data[i++] = LMI_INTEG_LEN;
  432. data[i++] = state(hdlc)->txseq =
  433. fr_lmi_nextseq(state(hdlc)->txseq);
  434. data[i++] = state(hdlc)->rxseq;
  435. if (dce && fullrep) {
  436. while (pvc) {
  437. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_PVCSTAT :
  438. LMI_ANSI_CISCO_PVCSTAT;
  439. data[i++] = stat_len;
  440. /* LMI start/restart */
  441. if (state(hdlc)->reliable && !pvc->state.exist) {
  442. pvc->state.exist = pvc->state.new = 1;
  443. fr_log_dlci_active(pvc);
  444. }
  445. /* ifconfig PVC up */
  446. if (pvc->open_count && !pvc->state.active &&
  447. pvc->state.exist && !pvc->state.new) {
  448. pvc_carrier(1, pvc);
  449. pvc->state.active = 1;
  450. fr_log_dlci_active(pvc);
  451. }
  452. if (lmi == LMI_CISCO) {
  453. data[i] = pvc->dlci >> 8;
  454. data[i + 1] = pvc->dlci & 0xFF;
  455. } else {
  456. data[i] = (pvc->dlci >> 4) & 0x3F;
  457. data[i + 1] = ((pvc->dlci << 3) & 0x78) | 0x80;
  458. data[i + 2] = 0x80;
  459. }
  460. if (pvc->state.new)
  461. data[i + 2] |= 0x08;
  462. else if (pvc->state.active)
  463. data[i + 2] |= 0x02;
  464. i += stat_len;
  465. pvc = pvc->next;
  466. }
  467. }
  468. skb_put(skb, i);
  469. skb->priority = TC_PRIO_CONTROL;
  470. skb->dev = dev;
  471. skb_reset_network_header(skb);
  472. dev_queue_xmit(skb);
  473. }
  474. static void fr_set_link_state(int reliable, struct net_device *dev)
  475. {
  476. hdlc_device *hdlc = dev_to_hdlc(dev);
  477. pvc_device *pvc = state(hdlc)->first_pvc;
  478. state(hdlc)->reliable = reliable;
  479. if (reliable) {
  480. netif_dormant_off(dev);
  481. state(hdlc)->n391cnt = 0; /* Request full status */
  482. state(hdlc)->dce_changed = 1;
  483. if (state(hdlc)->settings.lmi == LMI_NONE) {
  484. while (pvc) { /* Activate all PVCs */
  485. pvc_carrier(1, pvc);
  486. pvc->state.exist = pvc->state.active = 1;
  487. pvc->state.new = 0;
  488. pvc = pvc->next;
  489. }
  490. }
  491. } else {
  492. netif_dormant_on(dev);
  493. while (pvc) { /* Deactivate all PVCs */
  494. pvc_carrier(0, pvc);
  495. pvc->state.exist = pvc->state.active = 0;
  496. pvc->state.new = 0;
  497. if (!state(hdlc)->settings.dce)
  498. pvc->state.bandwidth = 0;
  499. pvc = pvc->next;
  500. }
  501. }
  502. }
  503. static void fr_timer(unsigned long arg)
  504. {
  505. struct net_device *dev = (struct net_device *)arg;
  506. hdlc_device *hdlc = dev_to_hdlc(dev);
  507. int i, cnt = 0, reliable;
  508. u32 list;
  509. if (state(hdlc)->settings.dce) {
  510. reliable = state(hdlc)->request &&
  511. time_before(jiffies, state(hdlc)->last_poll +
  512. state(hdlc)->settings.t392 * HZ);
  513. state(hdlc)->request = 0;
  514. } else {
  515. state(hdlc)->last_errors <<= 1; /* Shift the list */
  516. if (state(hdlc)->request) {
  517. if (state(hdlc)->reliable)
  518. printk(KERN_INFO "%s: No LMI status reply "
  519. "received\n", dev->name);
  520. state(hdlc)->last_errors |= 1;
  521. }
  522. list = state(hdlc)->last_errors;
  523. for (i = 0; i < state(hdlc)->settings.n393; i++, list >>= 1)
  524. cnt += (list & 1); /* errors count */
  525. reliable = (cnt < state(hdlc)->settings.n392);
  526. }
  527. if (state(hdlc)->reliable != reliable) {
  528. printk(KERN_INFO "%s: Link %sreliable\n", dev->name,
  529. reliable ? "" : "un");
  530. fr_set_link_state(reliable, dev);
  531. }
  532. if (state(hdlc)->settings.dce)
  533. state(hdlc)->timer.expires = jiffies +
  534. state(hdlc)->settings.t392 * HZ;
  535. else {
  536. if (state(hdlc)->n391cnt)
  537. state(hdlc)->n391cnt--;
  538. fr_lmi_send(dev, state(hdlc)->n391cnt == 0);
  539. state(hdlc)->last_poll = jiffies;
  540. state(hdlc)->request = 1;
  541. state(hdlc)->timer.expires = jiffies +
  542. state(hdlc)->settings.t391 * HZ;
  543. }
  544. state(hdlc)->timer.function = fr_timer;
  545. state(hdlc)->timer.data = arg;
  546. add_timer(&state(hdlc)->timer);
  547. }
  548. static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
  549. {
  550. hdlc_device *hdlc = dev_to_hdlc(dev);
  551. pvc_device *pvc;
  552. u8 rxseq, txseq;
  553. int lmi = state(hdlc)->settings.lmi;
  554. int dce = state(hdlc)->settings.dce;
  555. int stat_len = (lmi == LMI_CISCO) ? 6 : 3, reptype, error, no_ram, i;
  556. if (skb->len < (lmi == LMI_ANSI ? LMI_ANSI_LENGTH :
  557. LMI_CCITT_CISCO_LENGTH)) {
  558. printk(KERN_INFO "%s: Short LMI frame\n", dev->name);
  559. return 1;
  560. }
  561. if (skb->data[3] != (lmi == LMI_CISCO ? NLPID_CISCO_LMI :
  562. NLPID_CCITT_ANSI_LMI)) {
  563. printk(KERN_INFO "%s: Received non-LMI frame with LMI DLCI\n",
  564. dev->name);
  565. return 1;
  566. }
  567. if (skb->data[4] != LMI_CALLREF) {
  568. printk(KERN_INFO "%s: Invalid LMI Call reference (0x%02X)\n",
  569. dev->name, skb->data[4]);
  570. return 1;
  571. }
  572. if (skb->data[5] != (dce ? LMI_STATUS_ENQUIRY : LMI_STATUS)) {
  573. printk(KERN_INFO "%s: Invalid LMI Message type (0x%02X)\n",
  574. dev->name, skb->data[5]);
  575. return 1;
  576. }
  577. if (lmi == LMI_ANSI) {
  578. if (skb->data[6] != LMI_ANSI_LOCKSHIFT) {
  579. printk(KERN_INFO "%s: Not ANSI locking shift in LMI"
  580. " message (0x%02X)\n", dev->name, skb->data[6]);
  581. return 1;
  582. }
  583. i = 7;
  584. } else
  585. i = 6;
  586. if (skb->data[i] != (lmi == LMI_CCITT ? LMI_CCITT_REPTYPE :
  587. LMI_ANSI_CISCO_REPTYPE)) {
  588. printk(KERN_INFO "%s: Not an LMI Report type IE (0x%02X)\n",
  589. dev->name, skb->data[i]);
  590. return 1;
  591. }
  592. if (skb->data[++i] != LMI_REPT_LEN) {
  593. printk(KERN_INFO "%s: Invalid LMI Report type IE length"
  594. " (%u)\n", dev->name, skb->data[i]);
  595. return 1;
  596. }
  597. reptype = skb->data[++i];
  598. if (reptype != LMI_INTEGRITY && reptype != LMI_FULLREP) {
  599. printk(KERN_INFO "%s: Unsupported LMI Report type (0x%02X)\n",
  600. dev->name, reptype);
  601. return 1;
  602. }
  603. if (skb->data[++i] != (lmi == LMI_CCITT ? LMI_CCITT_ALIVE :
  604. LMI_ANSI_CISCO_ALIVE)) {
  605. printk(KERN_INFO "%s: Not an LMI Link integrity verification"
  606. " IE (0x%02X)\n", dev->name, skb->data[i]);
  607. return 1;
  608. }
  609. if (skb->data[++i] != LMI_INTEG_LEN) {
  610. printk(KERN_INFO "%s: Invalid LMI Link integrity verification"
  611. " IE length (%u)\n", dev->name, skb->data[i]);
  612. return 1;
  613. }
  614. i++;
  615. state(hdlc)->rxseq = skb->data[i++]; /* TX sequence from peer */
  616. rxseq = skb->data[i++]; /* Should confirm our sequence */
  617. txseq = state(hdlc)->txseq;
  618. if (dce)
  619. state(hdlc)->last_poll = jiffies;
  620. error = 0;
  621. if (!state(hdlc)->reliable)
  622. error = 1;
  623. if (rxseq == 0 || rxseq != txseq) { /* Ask for full report next time */
  624. state(hdlc)->n391cnt = 0;
  625. error = 1;
  626. }
  627. if (dce) {
  628. if (state(hdlc)->fullrep_sent && !error) {
  629. /* Stop sending full report - the last one has been confirmed by DTE */
  630. state(hdlc)->fullrep_sent = 0;
  631. pvc = state(hdlc)->first_pvc;
  632. while (pvc) {
  633. if (pvc->state.new) {
  634. pvc->state.new = 0;
  635. /* Tell DTE that new PVC is now active */
  636. state(hdlc)->dce_changed = 1;
  637. }
  638. pvc = pvc->next;
  639. }
  640. }
  641. if (state(hdlc)->dce_changed) {
  642. reptype = LMI_FULLREP;
  643. state(hdlc)->fullrep_sent = 1;
  644. state(hdlc)->dce_changed = 0;
  645. }
  646. state(hdlc)->request = 1; /* got request */
  647. fr_lmi_send(dev, reptype == LMI_FULLREP ? 1 : 0);
  648. return 0;
  649. }
  650. /* DTE */
  651. state(hdlc)->request = 0; /* got response, no request pending */
  652. if (error)
  653. return 0;
  654. if (reptype != LMI_FULLREP)
  655. return 0;
  656. pvc = state(hdlc)->first_pvc;
  657. while (pvc) {
  658. pvc->state.deleted = 1;
  659. pvc = pvc->next;
  660. }
  661. no_ram = 0;
  662. while (skb->len >= i + 2 + stat_len) {
  663. u16 dlci;
  664. u32 bw;
  665. unsigned int active, new;
  666. if (skb->data[i] != (lmi == LMI_CCITT ? LMI_CCITT_PVCSTAT :
  667. LMI_ANSI_CISCO_PVCSTAT)) {
  668. printk(KERN_INFO "%s: Not an LMI PVC status IE"
  669. " (0x%02X)\n", dev->name, skb->data[i]);
  670. return 1;
  671. }
  672. if (skb->data[++i] != stat_len) {
  673. printk(KERN_INFO "%s: Invalid LMI PVC status IE length"
  674. " (%u)\n", dev->name, skb->data[i]);
  675. return 1;
  676. }
  677. i++;
  678. new = !! (skb->data[i + 2] & 0x08);
  679. active = !! (skb->data[i + 2] & 0x02);
  680. if (lmi == LMI_CISCO) {
  681. dlci = (skb->data[i] << 8) | skb->data[i + 1];
  682. bw = (skb->data[i + 3] << 16) |
  683. (skb->data[i + 4] << 8) |
  684. (skb->data[i + 5]);
  685. } else {
  686. dlci = ((skb->data[i] & 0x3F) << 4) |
  687. ((skb->data[i + 1] & 0x78) >> 3);
  688. bw = 0;
  689. }
  690. pvc = add_pvc(dev, dlci);
  691. if (!pvc && !no_ram) {
  692. printk(KERN_WARNING
  693. "%s: Memory squeeze on fr_lmi_recv()\n",
  694. dev->name);
  695. no_ram = 1;
  696. }
  697. if (pvc) {
  698. pvc->state.exist = 1;
  699. pvc->state.deleted = 0;
  700. if (active != pvc->state.active ||
  701. new != pvc->state.new ||
  702. bw != pvc->state.bandwidth ||
  703. !pvc->state.exist) {
  704. pvc->state.new = new;
  705. pvc->state.active = active;
  706. pvc->state.bandwidth = bw;
  707. pvc_carrier(active, pvc);
  708. fr_log_dlci_active(pvc);
  709. }
  710. }
  711. i += stat_len;
  712. }
  713. pvc = state(hdlc)->first_pvc;
  714. while (pvc) {
  715. if (pvc->state.deleted && pvc->state.exist) {
  716. pvc_carrier(0, pvc);
  717. pvc->state.active = pvc->state.new = 0;
  718. pvc->state.exist = 0;
  719. pvc->state.bandwidth = 0;
  720. fr_log_dlci_active(pvc);
  721. }
  722. pvc = pvc->next;
  723. }
  724. /* Next full report after N391 polls */
  725. state(hdlc)->n391cnt = state(hdlc)->settings.n391;
  726. return 0;
  727. }
  728. static int fr_rx(struct sk_buff *skb)
  729. {
  730. struct net_device *frad = skb->dev;
  731. hdlc_device *hdlc = dev_to_hdlc(frad);
  732. fr_hdr *fh = (fr_hdr*)skb->data;
  733. u8 *data = skb->data;
  734. u16 dlci;
  735. pvc_device *pvc;
  736. struct net_device *dev = NULL;
  737. if (skb->len <= 4 || fh->ea1 || data[2] != FR_UI)
  738. goto rx_error;
  739. dlci = q922_to_dlci(skb->data);
  740. if ((dlci == LMI_CCITT_ANSI_DLCI &&
  741. (state(hdlc)->settings.lmi == LMI_ANSI ||
  742. state(hdlc)->settings.lmi == LMI_CCITT)) ||
  743. (dlci == LMI_CISCO_DLCI &&
  744. state(hdlc)->settings.lmi == LMI_CISCO)) {
  745. if (fr_lmi_recv(frad, skb))
  746. goto rx_error;
  747. dev_kfree_skb_any(skb);
  748. return NET_RX_SUCCESS;
  749. }
  750. pvc = find_pvc(hdlc, dlci);
  751. if (!pvc) {
  752. #ifdef DEBUG_PKT
  753. printk(KERN_INFO "%s: No PVC for received frame's DLCI %d\n",
  754. frad->name, dlci);
  755. #endif
  756. dev_kfree_skb_any(skb);
  757. return NET_RX_DROP;
  758. }
  759. if (pvc->state.fecn != fh->fecn) {
  760. #ifdef DEBUG_ECN
  761. printk(KERN_DEBUG "%s: DLCI %d FECN O%s\n", frad->name,
  762. dlci, fh->fecn ? "N" : "FF");
  763. #endif
  764. pvc->state.fecn ^= 1;
  765. }
  766. if (pvc->state.becn != fh->becn) {
  767. #ifdef DEBUG_ECN
  768. printk(KERN_DEBUG "%s: DLCI %d BECN O%s\n", frad->name,
  769. dlci, fh->becn ? "N" : "FF");
  770. #endif
  771. pvc->state.becn ^= 1;
  772. }
  773. if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
  774. frad->stats.rx_dropped++;
  775. return NET_RX_DROP;
  776. }
  777. if (data[3] == NLPID_IP) {
  778. skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */
  779. dev = pvc->main;
  780. skb->protocol = htons(ETH_P_IP);
  781. } else if (data[3] == NLPID_IPV6) {
  782. skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */
  783. dev = pvc->main;
  784. skb->protocol = htons(ETH_P_IPV6);
  785. } else if (skb->len > 10 && data[3] == FR_PAD &&
  786. data[4] == NLPID_SNAP && data[5] == FR_PAD) {
  787. u16 oui = ntohs(*(__be16*)(data + 6));
  788. u16 pid = ntohs(*(__be16*)(data + 8));
  789. skb_pull(skb, 10);
  790. switch ((((u32)oui) << 16) | pid) {
  791. case ETH_P_ARP: /* routed frame with SNAP */
  792. case ETH_P_IPX:
  793. case ETH_P_IP: /* a long variant */
  794. case ETH_P_IPV6:
  795. dev = pvc->main;
  796. skb->protocol = htons(pid);
  797. break;
  798. case 0x80C20007: /* bridged Ethernet frame */
  799. if ((dev = pvc->ether) != NULL)
  800. skb->protocol = eth_type_trans(skb, dev);
  801. break;
  802. default:
  803. printk(KERN_INFO "%s: Unsupported protocol, OUI=%x "
  804. "PID=%x\n", frad->name, oui, pid);
  805. dev_kfree_skb_any(skb);
  806. return NET_RX_DROP;
  807. }
  808. } else {
  809. printk(KERN_INFO "%s: Unsupported protocol, NLPID=%x "
  810. "length = %i\n", frad->name, data[3], skb->len);
  811. dev_kfree_skb_any(skb);
  812. return NET_RX_DROP;
  813. }
  814. if (dev) {
  815. dev->stats.rx_packets++; /* PVC traffic */
  816. dev->stats.rx_bytes += skb->len;
  817. if (pvc->state.becn)
  818. dev->stats.rx_compressed++;
  819. skb->dev = dev;
  820. netif_rx(skb);
  821. return NET_RX_SUCCESS;
  822. } else {
  823. dev_kfree_skb_any(skb);
  824. return NET_RX_DROP;
  825. }
  826. rx_error:
  827. frad->stats.rx_errors++; /* Mark error */
  828. dev_kfree_skb_any(skb);
  829. return NET_RX_DROP;
  830. }
  831. static void fr_start(struct net_device *dev)
  832. {
  833. hdlc_device *hdlc = dev_to_hdlc(dev);
  834. #ifdef DEBUG_LINK
  835. printk(KERN_DEBUG "fr_start\n");
  836. #endif
  837. if (state(hdlc)->settings.lmi != LMI_NONE) {
  838. state(hdlc)->reliable = 0;
  839. state(hdlc)->dce_changed = 1;
  840. state(hdlc)->request = 0;
  841. state(hdlc)->fullrep_sent = 0;
  842. state(hdlc)->last_errors = 0xFFFFFFFF;
  843. state(hdlc)->n391cnt = 0;
  844. state(hdlc)->txseq = state(hdlc)->rxseq = 0;
  845. init_timer(&state(hdlc)->timer);
  846. /* First poll after 1 s */
  847. state(hdlc)->timer.expires = jiffies + HZ;
  848. state(hdlc)->timer.function = fr_timer;
  849. state(hdlc)->timer.data = (unsigned long)dev;
  850. add_timer(&state(hdlc)->timer);
  851. } else
  852. fr_set_link_state(1, dev);
  853. }
  854. static void fr_stop(struct net_device *dev)
  855. {
  856. hdlc_device *hdlc = dev_to_hdlc(dev);
  857. #ifdef DEBUG_LINK
  858. printk(KERN_DEBUG "fr_stop\n");
  859. #endif
  860. if (state(hdlc)->settings.lmi != LMI_NONE)
  861. del_timer_sync(&state(hdlc)->timer);
  862. fr_set_link_state(0, dev);
  863. }
  864. static void fr_close(struct net_device *dev)
  865. {
  866. hdlc_device *hdlc = dev_to_hdlc(dev);
  867. pvc_device *pvc = state(hdlc)->first_pvc;
  868. while (pvc) { /* Shutdown all PVCs for this FRAD */
  869. if (pvc->main)
  870. dev_close(pvc->main);
  871. if (pvc->ether)
  872. dev_close(pvc->ether);
  873. pvc = pvc->next;
  874. }
  875. }
  876. static void pvc_setup(struct net_device *dev)
  877. {
  878. dev->type = ARPHRD_DLCI;
  879. dev->flags = IFF_POINTOPOINT;
  880. dev->hard_header_len = 10;
  881. dev->addr_len = 2;
  882. }
  883. static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
  884. {
  885. hdlc_device *hdlc = dev_to_hdlc(frad);
  886. pvc_device *pvc;
  887. struct net_device *dev;
  888. int result, used;
  889. if ((pvc = add_pvc(frad, dlci)) == NULL) {
  890. printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n",
  891. frad->name);
  892. return -ENOBUFS;
  893. }
  894. if (*get_dev_p(pvc, type))
  895. return -EEXIST;
  896. used = pvc_is_used(pvc);
  897. if (type == ARPHRD_ETHER)
  898. dev = alloc_netdev(0, "pvceth%d", ether_setup);
  899. else
  900. dev = alloc_netdev(0, "pvc%d", pvc_setup);
  901. if (!dev) {
  902. printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n",
  903. frad->name);
  904. delete_unused_pvcs(hdlc);
  905. return -ENOBUFS;
  906. }
  907. if (type == ARPHRD_ETHER)
  908. random_ether_addr(dev->dev_addr);
  909. else {
  910. *(__be16*)dev->dev_addr = htons(dlci);
  911. dlci_to_q922(dev->broadcast, dlci);
  912. }
  913. dev->hard_start_xmit = pvc_xmit;
  914. dev->open = pvc_open;
  915. dev->stop = pvc_close;
  916. dev->do_ioctl = pvc_ioctl;
  917. dev->change_mtu = pvc_change_mtu;
  918. dev->mtu = HDLC_MAX_MTU;
  919. dev->tx_queue_len = 0;
  920. dev->priv = pvc;
  921. result = dev_alloc_name(dev, dev->name);
  922. if (result < 0) {
  923. free_netdev(dev);
  924. delete_unused_pvcs(hdlc);
  925. return result;
  926. }
  927. if (register_netdevice(dev) != 0) {
  928. free_netdev(dev);
  929. delete_unused_pvcs(hdlc);
  930. return -EIO;
  931. }
  932. dev->destructor = free_netdev;
  933. *get_dev_p(pvc, type) = dev;
  934. if (!used) {
  935. state(hdlc)->dce_changed = 1;
  936. state(hdlc)->dce_pvc_count++;
  937. }
  938. return 0;
  939. }
  940. static int fr_del_pvc(hdlc_device *hdlc, unsigned int dlci, int type)
  941. {
  942. pvc_device *pvc;
  943. struct net_device *dev;
  944. if ((pvc = find_pvc(hdlc, dlci)) == NULL)
  945. return -ENOENT;
  946. if ((dev = *get_dev_p(pvc, type)) == NULL)
  947. return -ENOENT;
  948. if (dev->flags & IFF_UP)
  949. return -EBUSY; /* PVC in use */
  950. unregister_netdevice(dev); /* the destructor will free_netdev(dev) */
  951. *get_dev_p(pvc, type) = NULL;
  952. if (!pvc_is_used(pvc)) {
  953. state(hdlc)->dce_pvc_count--;
  954. state(hdlc)->dce_changed = 1;
  955. }
  956. delete_unused_pvcs(hdlc);
  957. return 0;
  958. }
  959. static void fr_destroy(struct net_device *frad)
  960. {
  961. hdlc_device *hdlc = dev_to_hdlc(frad);
  962. pvc_device *pvc = state(hdlc)->first_pvc;
  963. state(hdlc)->first_pvc = NULL; /* All PVCs destroyed */
  964. state(hdlc)->dce_pvc_count = 0;
  965. state(hdlc)->dce_changed = 1;
  966. while (pvc) {
  967. pvc_device *next = pvc->next;
  968. /* destructors will free_netdev() main and ether */
  969. if (pvc->main)
  970. unregister_netdevice(pvc->main);
  971. if (pvc->ether)
  972. unregister_netdevice(pvc->ether);
  973. kfree(pvc);
  974. pvc = next;
  975. }
  976. }
  977. static struct hdlc_proto proto = {
  978. .close = fr_close,
  979. .start = fr_start,
  980. .stop = fr_stop,
  981. .detach = fr_destroy,
  982. .ioctl = fr_ioctl,
  983. .netif_rx = fr_rx,
  984. .module = THIS_MODULE,
  985. };
  986. static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
  987. {
  988. fr_proto __user *fr_s = ifr->ifr_settings.ifs_ifsu.fr;
  989. const size_t size = sizeof(fr_proto);
  990. fr_proto new_settings;
  991. hdlc_device *hdlc = dev_to_hdlc(dev);
  992. fr_proto_pvc pvc;
  993. int result;
  994. switch (ifr->ifr_settings.type) {
  995. case IF_GET_PROTO:
  996. if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
  997. return -EINVAL;
  998. ifr->ifr_settings.type = IF_PROTO_FR;
  999. if (ifr->ifr_settings.size < size) {
  1000. ifr->ifr_settings.size = size; /* data size wanted */
  1001. return -ENOBUFS;
  1002. }
  1003. if (copy_to_user(fr_s, &state(hdlc)->settings, size))
  1004. return -EFAULT;
  1005. return 0;
  1006. case IF_PROTO_FR:
  1007. if(!capable(CAP_NET_ADMIN))
  1008. return -EPERM;
  1009. if(dev->flags & IFF_UP)
  1010. return -EBUSY;
  1011. if (copy_from_user(&new_settings, fr_s, size))
  1012. return -EFAULT;
  1013. if (new_settings.lmi == LMI_DEFAULT)
  1014. new_settings.lmi = LMI_ANSI;
  1015. if ((new_settings.lmi != LMI_NONE &&
  1016. new_settings.lmi != LMI_ANSI &&
  1017. new_settings.lmi != LMI_CCITT &&
  1018. new_settings.lmi != LMI_CISCO) ||
  1019. new_settings.t391 < 1 ||
  1020. new_settings.t392 < 2 ||
  1021. new_settings.n391 < 1 ||
  1022. new_settings.n392 < 1 ||
  1023. new_settings.n393 < new_settings.n392 ||
  1024. new_settings.n393 > 32 ||
  1025. (new_settings.dce != 0 &&
  1026. new_settings.dce != 1))
  1027. return -EINVAL;
  1028. result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT);
  1029. if (result)
  1030. return result;
  1031. if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */
  1032. result = attach_hdlc_protocol(dev, &proto,
  1033. sizeof(struct frad_state));
  1034. if (result)
  1035. return result;
  1036. state(hdlc)->first_pvc = NULL;
  1037. state(hdlc)->dce_pvc_count = 0;
  1038. }
  1039. memcpy(&state(hdlc)->settings, &new_settings, size);
  1040. dev->hard_start_xmit = hdlc->xmit;
  1041. dev->type = ARPHRD_FRAD;
  1042. return 0;
  1043. case IF_PROTO_FR_ADD_PVC:
  1044. case IF_PROTO_FR_DEL_PVC:
  1045. case IF_PROTO_FR_ADD_ETH_PVC:
  1046. case IF_PROTO_FR_DEL_ETH_PVC:
  1047. if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
  1048. return -EINVAL;
  1049. if(!capable(CAP_NET_ADMIN))
  1050. return -EPERM;
  1051. if (copy_from_user(&pvc, ifr->ifr_settings.ifs_ifsu.fr_pvc,
  1052. sizeof(fr_proto_pvc)))
  1053. return -EFAULT;
  1054. if (pvc.dlci <= 0 || pvc.dlci >= 1024)
  1055. return -EINVAL; /* Only 10 bits, DLCI 0 reserved */
  1056. if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC ||
  1057. ifr->ifr_settings.type == IF_PROTO_FR_DEL_ETH_PVC)
  1058. result = ARPHRD_ETHER; /* bridged Ethernet device */
  1059. else
  1060. result = ARPHRD_DLCI;
  1061. if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_PVC ||
  1062. ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC)
  1063. return fr_add_pvc(dev, pvc.dlci, result);
  1064. else
  1065. return fr_del_pvc(hdlc, pvc.dlci, result);
  1066. }
  1067. return -EINVAL;
  1068. }
  1069. static int __init mod_init(void)
  1070. {
  1071. register_hdlc_protocol(&proto);
  1072. return 0;
  1073. }
  1074. static void __exit mod_exit(void)
  1075. {
  1076. unregister_hdlc_protocol(&proto);
  1077. }
  1078. module_init(mod_init);
  1079. module_exit(mod_exit);
  1080. MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
  1081. MODULE_DESCRIPTION("Frame-Relay protocol support for generic HDLC");
  1082. MODULE_LICENSE("GPL v2");