hdlc_fr.c 30 KB

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