hdlc_fr.c 29 KB

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