hdlc_fr.c 29 KB

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