isdn_ppp.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054
  1. /* $Id: isdn_ppp.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
  2. *
  3. * Linux ISDN subsystem, functions for synchronous PPP (linklevel).
  4. *
  5. * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #include <linux/isdn.h>
  12. #include <linux/poll.h>
  13. #include <linux/ppp-comp.h>
  14. #include <linux/slab.h>
  15. #ifdef CONFIG_IPPP_FILTER
  16. #include <linux/filter.h>
  17. #endif
  18. #include "isdn_common.h"
  19. #include "isdn_ppp.h"
  20. #include "isdn_net.h"
  21. #ifndef PPP_IPX
  22. #define PPP_IPX 0x002b
  23. #endif
  24. /* Prototypes */
  25. static int isdn_ppp_fill_rq(unsigned char *buf, int len, int proto, int slot);
  26. static int isdn_ppp_closewait(int slot);
  27. static void isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp,
  28. struct sk_buff *skb, int proto);
  29. static int isdn_ppp_if_get_unit(char *namebuf);
  30. static int isdn_ppp_set_compressor(struct ippp_struct *is, struct isdn_ppp_comp_data *);
  31. static struct sk_buff *isdn_ppp_decompress(struct sk_buff *,
  32. struct ippp_struct *, struct ippp_struct *, int *proto);
  33. static void isdn_ppp_receive_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
  34. struct sk_buff *skb, int proto);
  35. static struct sk_buff *isdn_ppp_compress(struct sk_buff *skb_in, int *proto,
  36. struct ippp_struct *is, struct ippp_struct *master, int type);
  37. static void isdn_ppp_send_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
  38. struct sk_buff *skb);
  39. /* New CCP stuff */
  40. static void isdn_ppp_ccp_kickup(struct ippp_struct *is);
  41. static void isdn_ppp_ccp_xmit_reset(struct ippp_struct *is, int proto,
  42. unsigned char code, unsigned char id,
  43. unsigned char *data, int len);
  44. static struct ippp_ccp_reset *isdn_ppp_ccp_reset_alloc(struct ippp_struct *is);
  45. static void isdn_ppp_ccp_reset_free(struct ippp_struct *is);
  46. static void isdn_ppp_ccp_reset_free_state(struct ippp_struct *is,
  47. unsigned char id);
  48. static void isdn_ppp_ccp_timer_callback(unsigned long closure);
  49. static struct ippp_ccp_reset_state *isdn_ppp_ccp_reset_alloc_state(struct ippp_struct *is,
  50. unsigned char id);
  51. static void isdn_ppp_ccp_reset_trans(struct ippp_struct *is,
  52. struct isdn_ppp_resetparams *rp);
  53. static void isdn_ppp_ccp_reset_ack_rcvd(struct ippp_struct *is,
  54. unsigned char id);
  55. #ifdef CONFIG_ISDN_MPP
  56. static ippp_bundle *isdn_ppp_bundle_arr = NULL;
  57. static int isdn_ppp_mp_bundle_array_init(void);
  58. static int isdn_ppp_mp_init(isdn_net_local *lp, ippp_bundle *add_to);
  59. static void isdn_ppp_mp_receive(isdn_net_dev *net_dev, isdn_net_local *lp,
  60. struct sk_buff *skb);
  61. static void isdn_ppp_mp_cleanup(isdn_net_local *lp);
  62. static int isdn_ppp_bundle(struct ippp_struct *, int unit);
  63. #endif /* CONFIG_ISDN_MPP */
  64. char *isdn_ppp_revision = "$Revision: 1.1.2.3 $";
  65. static struct ippp_struct *ippp_table[ISDN_MAX_CHANNELS];
  66. static struct isdn_ppp_compressor *ipc_head = NULL;
  67. /*
  68. * frame log (debug)
  69. */
  70. static void
  71. isdn_ppp_frame_log(char *info, char *data, int len, int maxlen, int unit, int slot)
  72. {
  73. int cnt,
  74. j,
  75. i;
  76. char buf[80];
  77. if (len < maxlen)
  78. maxlen = len;
  79. for (i = 0, cnt = 0; cnt < maxlen; i++) {
  80. for (j = 0; j < 16 && cnt < maxlen; j++, cnt++)
  81. sprintf(buf + j * 3, "%02x ", (unsigned char)data[cnt]);
  82. printk(KERN_DEBUG "[%d/%d].%s[%d]: %s\n", unit, slot, info, i, buf);
  83. }
  84. }
  85. /*
  86. * unbind isdn_net_local <=> ippp-device
  87. * note: it can happen, that we hangup/free the master before the slaves
  88. * in this case we bind another lp to the master device
  89. */
  90. int
  91. isdn_ppp_free(isdn_net_local *lp)
  92. {
  93. struct ippp_struct *is;
  94. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  95. printk(KERN_ERR "%s: ppp_slot(%d) out of range\n",
  96. __func__, lp->ppp_slot);
  97. return 0;
  98. }
  99. #ifdef CONFIG_ISDN_MPP
  100. spin_lock(&lp->netdev->pb->lock);
  101. #endif
  102. isdn_net_rm_from_bundle(lp);
  103. #ifdef CONFIG_ISDN_MPP
  104. if (lp->netdev->pb->ref_ct == 1) /* last link in queue? */
  105. isdn_ppp_mp_cleanup(lp);
  106. lp->netdev->pb->ref_ct--;
  107. spin_unlock(&lp->netdev->pb->lock);
  108. #endif /* CONFIG_ISDN_MPP */
  109. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  110. printk(KERN_ERR "%s: ppp_slot(%d) now invalid\n",
  111. __func__, lp->ppp_slot);
  112. return 0;
  113. }
  114. is = ippp_table[lp->ppp_slot];
  115. if ((is->state & IPPP_CONNECT))
  116. isdn_ppp_closewait(lp->ppp_slot); /* force wakeup on ippp device */
  117. else if (is->state & IPPP_ASSIGNED)
  118. is->state = IPPP_OPEN; /* fallback to 'OPEN but not ASSIGNED' state */
  119. if (is->debug & 0x1)
  120. printk(KERN_DEBUG "isdn_ppp_free %d %lx %lx\n", lp->ppp_slot, (long) lp, (long) is->lp);
  121. is->lp = NULL; /* link is down .. set lp to NULL */
  122. lp->ppp_slot = -1; /* is this OK ?? */
  123. return 0;
  124. }
  125. /*
  126. * bind isdn_net_local <=> ippp-device
  127. *
  128. * This function is allways called with holding dev->lock so
  129. * no additional lock is needed
  130. */
  131. int
  132. isdn_ppp_bind(isdn_net_local *lp)
  133. {
  134. int i;
  135. int unit = 0;
  136. struct ippp_struct *is;
  137. int retval;
  138. if (lp->pppbind < 0) { /* device bounded to ippp device ? */
  139. isdn_net_dev *net_dev = dev->netdev;
  140. char exclusive[ISDN_MAX_CHANNELS]; /* exclusive flags */
  141. memset(exclusive, 0, ISDN_MAX_CHANNELS);
  142. while (net_dev) { /* step through net devices to find exclusive minors */
  143. isdn_net_local *lp = net_dev->local;
  144. if (lp->pppbind >= 0)
  145. exclusive[lp->pppbind] = 1;
  146. net_dev = net_dev->next;
  147. }
  148. /*
  149. * search a free device / slot
  150. */
  151. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  152. if (ippp_table[i]->state == IPPP_OPEN && !exclusive[ippp_table[i]->minor]) { /* OPEN, but not connected! */
  153. break;
  154. }
  155. }
  156. } else {
  157. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  158. if (ippp_table[i]->minor == lp->pppbind &&
  159. (ippp_table[i]->state & IPPP_OPEN) == IPPP_OPEN)
  160. break;
  161. }
  162. }
  163. if (i >= ISDN_MAX_CHANNELS) {
  164. printk(KERN_WARNING "isdn_ppp_bind: Can't find a (free) connection to the ipppd daemon.\n");
  165. retval = -1;
  166. goto out;
  167. }
  168. /* get unit number from interface name .. ugly! */
  169. unit = isdn_ppp_if_get_unit(lp->netdev->dev->name);
  170. if (unit < 0) {
  171. printk(KERN_ERR "isdn_ppp_bind: illegal interface name %s.\n",
  172. lp->netdev->dev->name);
  173. retval = -1;
  174. goto out;
  175. }
  176. lp->ppp_slot = i;
  177. is = ippp_table[i];
  178. is->lp = lp;
  179. is->unit = unit;
  180. is->state = IPPP_OPEN | IPPP_ASSIGNED; /* assigned to a netdevice but not connected */
  181. #ifdef CONFIG_ISDN_MPP
  182. retval = isdn_ppp_mp_init(lp, NULL);
  183. if (retval < 0)
  184. goto out;
  185. #endif /* CONFIG_ISDN_MPP */
  186. retval = lp->ppp_slot;
  187. out:
  188. return retval;
  189. }
  190. /*
  191. * kick the ipppd on the device
  192. * (wakes up daemon after B-channel connect)
  193. */
  194. void
  195. isdn_ppp_wakeup_daemon(isdn_net_local *lp)
  196. {
  197. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  198. printk(KERN_ERR "%s: ppp_slot(%d) out of range\n",
  199. __func__, lp->ppp_slot);
  200. return;
  201. }
  202. ippp_table[lp->ppp_slot]->state = IPPP_OPEN | IPPP_CONNECT | IPPP_NOBLOCK;
  203. wake_up_interruptible(&ippp_table[lp->ppp_slot]->wq);
  204. }
  205. /*
  206. * there was a hangup on the netdevice
  207. * force wakeup of the ippp device
  208. * go into 'device waits for release' state
  209. */
  210. static int
  211. isdn_ppp_closewait(int slot)
  212. {
  213. struct ippp_struct *is;
  214. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  215. printk(KERN_ERR "%s: slot(%d) out of range\n",
  216. __func__, slot);
  217. return 0;
  218. }
  219. is = ippp_table[slot];
  220. if (is->state)
  221. wake_up_interruptible(&is->wq);
  222. is->state = IPPP_CLOSEWAIT;
  223. return 1;
  224. }
  225. /*
  226. * isdn_ppp_find_slot / isdn_ppp_free_slot
  227. */
  228. static int
  229. isdn_ppp_get_slot(void)
  230. {
  231. int i;
  232. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  233. if (!ippp_table[i]->state)
  234. return i;
  235. }
  236. return -1;
  237. }
  238. /*
  239. * isdn_ppp_open
  240. */
  241. int
  242. isdn_ppp_open(int min, struct file *file)
  243. {
  244. int slot;
  245. struct ippp_struct *is;
  246. if (min < 0 || min >= ISDN_MAX_CHANNELS)
  247. return -ENODEV;
  248. slot = isdn_ppp_get_slot();
  249. if (slot < 0) {
  250. return -EBUSY;
  251. }
  252. is = file->private_data = ippp_table[slot];
  253. printk(KERN_DEBUG "ippp, open, slot: %d, minor: %d, state: %04x\n",
  254. slot, min, is->state);
  255. /* compression stuff */
  256. is->link_compressor = is->compressor = NULL;
  257. is->link_decompressor = is->decompressor = NULL;
  258. is->link_comp_stat = is->comp_stat = NULL;
  259. is->link_decomp_stat = is->decomp_stat = NULL;
  260. is->compflags = 0;
  261. is->reset = isdn_ppp_ccp_reset_alloc(is);
  262. if (!is->reset)
  263. return -ENOMEM;
  264. is->lp = NULL;
  265. is->mp_seqno = 0; /* MP sequence number */
  266. is->pppcfg = 0; /* ppp configuration */
  267. is->mpppcfg = 0; /* mppp configuration */
  268. is->last_link_seqno = -1; /* MP: maybe set to Bundle-MIN, when joining a bundle ?? */
  269. is->unit = -1; /* set, when we have our interface */
  270. is->mru = 1524; /* MRU, default 1524 */
  271. is->maxcid = 16; /* VJ: maxcid */
  272. is->tk = current;
  273. init_waitqueue_head(&is->wq);
  274. is->first = is->rq + NUM_RCV_BUFFS - 1; /* receive queue */
  275. is->last = is->rq;
  276. is->minor = min;
  277. #ifdef CONFIG_ISDN_PPP_VJ
  278. /*
  279. * VJ header compression init
  280. */
  281. is->slcomp = slhc_init(16, 16); /* not necessary for 2. link in bundle */
  282. if (IS_ERR(is->slcomp)) {
  283. isdn_ppp_ccp_reset_free(is);
  284. return PTR_ERR(is->slcomp);
  285. }
  286. #endif
  287. #ifdef CONFIG_IPPP_FILTER
  288. is->pass_filter = NULL;
  289. is->active_filter = NULL;
  290. #endif
  291. is->state = IPPP_OPEN;
  292. return 0;
  293. }
  294. /*
  295. * release ippp device
  296. */
  297. void
  298. isdn_ppp_release(int min, struct file *file)
  299. {
  300. int i;
  301. struct ippp_struct *is;
  302. if (min < 0 || min >= ISDN_MAX_CHANNELS)
  303. return;
  304. is = file->private_data;
  305. if (!is) {
  306. printk(KERN_ERR "%s: no file->private_data\n", __func__);
  307. return;
  308. }
  309. if (is->debug & 0x1)
  310. printk(KERN_DEBUG "ippp: release, minor: %d %lx\n", min, (long) is->lp);
  311. if (is->lp) { /* a lp address says: this link is still up */
  312. isdn_net_dev *p = is->lp->netdev;
  313. if (!p) {
  314. printk(KERN_ERR "%s: no lp->netdev\n", __func__);
  315. return;
  316. }
  317. is->state &= ~IPPP_CONNECT; /* -> effect: no call of wakeup */
  318. /*
  319. * isdn_net_hangup() calls isdn_ppp_free()
  320. * isdn_ppp_free() sets is->lp to NULL and lp->ppp_slot to -1
  321. * removing the IPPP_CONNECT flag omits calling of isdn_ppp_wakeup_daemon()
  322. */
  323. isdn_net_hangup(p->dev);
  324. }
  325. for (i = 0; i < NUM_RCV_BUFFS; i++) {
  326. kfree(is->rq[i].buf);
  327. is->rq[i].buf = NULL;
  328. }
  329. is->first = is->rq + NUM_RCV_BUFFS - 1; /* receive queue */
  330. is->last = is->rq;
  331. #ifdef CONFIG_ISDN_PPP_VJ
  332. /* TODO: if this was the previous master: link the slcomp to the new master */
  333. slhc_free(is->slcomp);
  334. is->slcomp = NULL;
  335. #endif
  336. #ifdef CONFIG_IPPP_FILTER
  337. if (is->pass_filter) {
  338. bpf_prog_destroy(is->pass_filter);
  339. is->pass_filter = NULL;
  340. }
  341. if (is->active_filter) {
  342. bpf_prog_destroy(is->active_filter);
  343. is->active_filter = NULL;
  344. }
  345. #endif
  346. /* TODO: if this was the previous master: link the stuff to the new master */
  347. if (is->comp_stat)
  348. is->compressor->free(is->comp_stat);
  349. if (is->link_comp_stat)
  350. is->link_compressor->free(is->link_comp_stat);
  351. if (is->link_decomp_stat)
  352. is->link_decompressor->free(is->link_decomp_stat);
  353. if (is->decomp_stat)
  354. is->decompressor->free(is->decomp_stat);
  355. is->compressor = is->link_compressor = NULL;
  356. is->decompressor = is->link_decompressor = NULL;
  357. is->comp_stat = is->link_comp_stat = NULL;
  358. is->decomp_stat = is->link_decomp_stat = NULL;
  359. /* Clean up if necessary */
  360. if (is->reset)
  361. isdn_ppp_ccp_reset_free(is);
  362. /* this slot is ready for new connections */
  363. is->state = 0;
  364. }
  365. /*
  366. * get_arg .. ioctl helper
  367. */
  368. static int
  369. get_arg(void __user *b, void *val, int len)
  370. {
  371. if (len <= 0)
  372. len = sizeof(void *);
  373. if (copy_from_user(val, b, len))
  374. return -EFAULT;
  375. return 0;
  376. }
  377. /*
  378. * set arg .. ioctl helper
  379. */
  380. static int
  381. set_arg(void __user *b, void *val, int len)
  382. {
  383. if (len <= 0)
  384. len = sizeof(void *);
  385. if (copy_to_user(b, val, len))
  386. return -EFAULT;
  387. return 0;
  388. }
  389. #ifdef CONFIG_IPPP_FILTER
  390. static int get_filter(void __user *arg, struct sock_filter **p)
  391. {
  392. struct sock_fprog uprog;
  393. struct sock_filter *code = NULL;
  394. int len;
  395. if (copy_from_user(&uprog, arg, sizeof(uprog)))
  396. return -EFAULT;
  397. if (!uprog.len) {
  398. *p = NULL;
  399. return 0;
  400. }
  401. /* uprog.len is unsigned short, so no overflow here */
  402. len = uprog.len * sizeof(struct sock_filter);
  403. code = memdup_user(uprog.filter, len);
  404. if (IS_ERR(code))
  405. return PTR_ERR(code);
  406. *p = code;
  407. return uprog.len;
  408. }
  409. #endif /* CONFIG_IPPP_FILTER */
  410. /*
  411. * ippp device ioctl
  412. */
  413. int
  414. isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
  415. {
  416. unsigned long val;
  417. int r, i, j;
  418. struct ippp_struct *is;
  419. isdn_net_local *lp;
  420. struct isdn_ppp_comp_data data;
  421. void __user *argp = (void __user *)arg;
  422. is = file->private_data;
  423. lp = is->lp;
  424. if (is->debug & 0x1)
  425. printk(KERN_DEBUG "isdn_ppp_ioctl: minor: %d cmd: %x state: %x\n", min, cmd, is->state);
  426. if (!(is->state & IPPP_OPEN))
  427. return -EINVAL;
  428. switch (cmd) {
  429. case PPPIOCBUNDLE:
  430. #ifdef CONFIG_ISDN_MPP
  431. if (!(is->state & IPPP_CONNECT))
  432. return -EINVAL;
  433. if ((r = get_arg(argp, &val, sizeof(val))))
  434. return r;
  435. printk(KERN_DEBUG "iPPP-bundle: minor: %d, slave unit: %d, master unit: %d\n",
  436. (int) min, (int) is->unit, (int) val);
  437. return isdn_ppp_bundle(is, val);
  438. #else
  439. return -1;
  440. #endif
  441. break;
  442. case PPPIOCGUNIT: /* get ppp/isdn unit number */
  443. if ((r = set_arg(argp, &is->unit, sizeof(is->unit))))
  444. return r;
  445. break;
  446. case PPPIOCGIFNAME:
  447. if (!lp)
  448. return -EINVAL;
  449. if ((r = set_arg(argp, lp->netdev->dev->name,
  450. strlen(lp->netdev->dev->name))))
  451. return r;
  452. break;
  453. case PPPIOCGMPFLAGS: /* get configuration flags */
  454. if ((r = set_arg(argp, &is->mpppcfg, sizeof(is->mpppcfg))))
  455. return r;
  456. break;
  457. case PPPIOCSMPFLAGS: /* set configuration flags */
  458. if ((r = get_arg(argp, &val, sizeof(val))))
  459. return r;
  460. is->mpppcfg = val;
  461. break;
  462. case PPPIOCGFLAGS: /* get configuration flags */
  463. if ((r = set_arg(argp, &is->pppcfg, sizeof(is->pppcfg))))
  464. return r;
  465. break;
  466. case PPPIOCSFLAGS: /* set configuration flags */
  467. if ((r = get_arg(argp, &val, sizeof(val)))) {
  468. return r;
  469. }
  470. if (val & SC_ENABLE_IP && !(is->pppcfg & SC_ENABLE_IP) && (is->state & IPPP_CONNECT)) {
  471. if (lp) {
  472. /* OK .. we are ready to send buffers */
  473. is->pppcfg = val; /* isdn_ppp_xmit test for SC_ENABLE_IP !!! */
  474. netif_wake_queue(lp->netdev->dev);
  475. break;
  476. }
  477. }
  478. is->pppcfg = val;
  479. break;
  480. case PPPIOCGIDLE: /* get idle time information */
  481. if (lp) {
  482. struct ppp_idle pidle;
  483. pidle.xmit_idle = pidle.recv_idle = lp->huptimer;
  484. if ((r = set_arg(argp, &pidle, sizeof(struct ppp_idle))))
  485. return r;
  486. }
  487. break;
  488. case PPPIOCSMRU: /* set receive unit size for PPP */
  489. if ((r = get_arg(argp, &val, sizeof(val))))
  490. return r;
  491. is->mru = val;
  492. break;
  493. case PPPIOCSMPMRU:
  494. break;
  495. case PPPIOCSMPMTU:
  496. break;
  497. case PPPIOCSMAXCID: /* set the maximum compression slot id */
  498. if ((r = get_arg(argp, &val, sizeof(val))))
  499. return r;
  500. val++;
  501. if (is->maxcid != val) {
  502. #ifdef CONFIG_ISDN_PPP_VJ
  503. struct slcompress *sltmp;
  504. #endif
  505. if (is->debug & 0x1)
  506. printk(KERN_DEBUG "ippp, ioctl: changed MAXCID to %ld\n", val);
  507. is->maxcid = val;
  508. #ifdef CONFIG_ISDN_PPP_VJ
  509. sltmp = slhc_init(16, val);
  510. if (IS_ERR(sltmp))
  511. return PTR_ERR(sltmp);
  512. if (is->slcomp)
  513. slhc_free(is->slcomp);
  514. is->slcomp = sltmp;
  515. #endif
  516. }
  517. break;
  518. case PPPIOCGDEBUG:
  519. if ((r = set_arg(argp, &is->debug, sizeof(is->debug))))
  520. return r;
  521. break;
  522. case PPPIOCSDEBUG:
  523. if ((r = get_arg(argp, &val, sizeof(val))))
  524. return r;
  525. is->debug = val;
  526. break;
  527. case PPPIOCGCOMPRESSORS:
  528. {
  529. unsigned long protos[8] = {0,};
  530. struct isdn_ppp_compressor *ipc = ipc_head;
  531. while (ipc) {
  532. j = ipc->num / (sizeof(long) * 8);
  533. i = ipc->num % (sizeof(long) * 8);
  534. if (j < 8)
  535. protos[j] |= (1UL << i);
  536. ipc = ipc->next;
  537. }
  538. if ((r = set_arg(argp, protos, 8 * sizeof(long))))
  539. return r;
  540. }
  541. break;
  542. case PPPIOCSCOMPRESSOR:
  543. if ((r = get_arg(argp, &data, sizeof(struct isdn_ppp_comp_data))))
  544. return r;
  545. return isdn_ppp_set_compressor(is, &data);
  546. case PPPIOCGCALLINFO:
  547. {
  548. struct pppcallinfo pci;
  549. memset((char *)&pci, 0, sizeof(struct pppcallinfo));
  550. if (lp)
  551. {
  552. strncpy(pci.local_num, lp->msn, 63);
  553. if (lp->dial) {
  554. strncpy(pci.remote_num, lp->dial->num, 63);
  555. }
  556. pci.charge_units = lp->charge;
  557. if (lp->outgoing)
  558. pci.calltype = CALLTYPE_OUTGOING;
  559. else
  560. pci.calltype = CALLTYPE_INCOMING;
  561. if (lp->flags & ISDN_NET_CALLBACK)
  562. pci.calltype |= CALLTYPE_CALLBACK;
  563. }
  564. return set_arg(argp, &pci, sizeof(struct pppcallinfo));
  565. }
  566. #ifdef CONFIG_IPPP_FILTER
  567. case PPPIOCSPASS:
  568. {
  569. struct sock_fprog_kern fprog;
  570. struct sock_filter *code;
  571. int err, len = get_filter(argp, &code);
  572. if (len < 0)
  573. return len;
  574. fprog.len = len;
  575. fprog.filter = code;
  576. if (is->pass_filter) {
  577. bpf_prog_destroy(is->pass_filter);
  578. is->pass_filter = NULL;
  579. }
  580. if (fprog.filter != NULL)
  581. err = bpf_prog_create(&is->pass_filter, &fprog);
  582. else
  583. err = 0;
  584. kfree(code);
  585. return err;
  586. }
  587. case PPPIOCSACTIVE:
  588. {
  589. struct sock_fprog_kern fprog;
  590. struct sock_filter *code;
  591. int err, len = get_filter(argp, &code);
  592. if (len < 0)
  593. return len;
  594. fprog.len = len;
  595. fprog.filter = code;
  596. if (is->active_filter) {
  597. bpf_prog_destroy(is->active_filter);
  598. is->active_filter = NULL;
  599. }
  600. if (fprog.filter != NULL)
  601. err = bpf_prog_create(&is->active_filter, &fprog);
  602. else
  603. err = 0;
  604. kfree(code);
  605. return err;
  606. }
  607. #endif /* CONFIG_IPPP_FILTER */
  608. default:
  609. break;
  610. }
  611. return 0;
  612. }
  613. unsigned int
  614. isdn_ppp_poll(struct file *file, poll_table *wait)
  615. {
  616. u_int mask;
  617. struct ippp_buf_queue *bf, *bl;
  618. u_long flags;
  619. struct ippp_struct *is;
  620. is = file->private_data;
  621. if (is->debug & 0x2)
  622. printk(KERN_DEBUG "isdn_ppp_poll: minor: %d\n",
  623. iminor(file_inode(file)));
  624. /* just registers wait_queue hook. This doesn't really wait. */
  625. poll_wait(file, &is->wq, wait);
  626. if (!(is->state & IPPP_OPEN)) {
  627. if (is->state == IPPP_CLOSEWAIT)
  628. return POLLHUP;
  629. printk(KERN_DEBUG "isdn_ppp: device not open\n");
  630. return POLLERR;
  631. }
  632. /* we're always ready to send .. */
  633. mask = POLLOUT | POLLWRNORM;
  634. spin_lock_irqsave(&is->buflock, flags);
  635. bl = is->last;
  636. bf = is->first;
  637. /*
  638. * if IPPP_NOBLOCK is set we return even if we have nothing to read
  639. */
  640. if (bf->next != bl || (is->state & IPPP_NOBLOCK)) {
  641. is->state &= ~IPPP_NOBLOCK;
  642. mask |= POLLIN | POLLRDNORM;
  643. }
  644. spin_unlock_irqrestore(&is->buflock, flags);
  645. return mask;
  646. }
  647. /*
  648. * fill up isdn_ppp_read() queue ..
  649. */
  650. static int
  651. isdn_ppp_fill_rq(unsigned char *buf, int len, int proto, int slot)
  652. {
  653. struct ippp_buf_queue *bf, *bl;
  654. u_long flags;
  655. u_char *nbuf;
  656. struct ippp_struct *is;
  657. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  658. printk(KERN_WARNING "ippp: illegal slot(%d).\n", slot);
  659. return 0;
  660. }
  661. is = ippp_table[slot];
  662. if (!(is->state & IPPP_CONNECT)) {
  663. printk(KERN_DEBUG "ippp: device not activated.\n");
  664. return 0;
  665. }
  666. nbuf = kmalloc(len + 4, GFP_ATOMIC);
  667. if (!nbuf) {
  668. printk(KERN_WARNING "ippp: Can't alloc buf\n");
  669. return 0;
  670. }
  671. nbuf[0] = PPP_ALLSTATIONS;
  672. nbuf[1] = PPP_UI;
  673. nbuf[2] = proto >> 8;
  674. nbuf[3] = proto & 0xff;
  675. memcpy(nbuf + 4, buf, len);
  676. spin_lock_irqsave(&is->buflock, flags);
  677. bf = is->first;
  678. bl = is->last;
  679. if (bf == bl) {
  680. printk(KERN_WARNING "ippp: Queue is full; discarding first buffer\n");
  681. bf = bf->next;
  682. kfree(bf->buf);
  683. is->first = bf;
  684. }
  685. bl->buf = (char *) nbuf;
  686. bl->len = len + 4;
  687. is->last = bl->next;
  688. spin_unlock_irqrestore(&is->buflock, flags);
  689. wake_up_interruptible(&is->wq);
  690. return len;
  691. }
  692. /*
  693. * read() .. non-blocking: ipppd calls it only after select()
  694. * reports, that there is data
  695. */
  696. int
  697. isdn_ppp_read(int min, struct file *file, char __user *buf, int count)
  698. {
  699. struct ippp_struct *is;
  700. struct ippp_buf_queue *b;
  701. u_long flags;
  702. u_char *save_buf;
  703. is = file->private_data;
  704. if (!(is->state & IPPP_OPEN))
  705. return 0;
  706. if (!access_ok(VERIFY_WRITE, buf, count))
  707. return -EFAULT;
  708. spin_lock_irqsave(&is->buflock, flags);
  709. b = is->first->next;
  710. save_buf = b->buf;
  711. if (!save_buf) {
  712. spin_unlock_irqrestore(&is->buflock, flags);
  713. return -EAGAIN;
  714. }
  715. if (b->len < count)
  716. count = b->len;
  717. b->buf = NULL;
  718. is->first = b;
  719. spin_unlock_irqrestore(&is->buflock, flags);
  720. if (copy_to_user(buf, save_buf, count))
  721. count = -EFAULT;
  722. kfree(save_buf);
  723. return count;
  724. }
  725. /*
  726. * ipppd wanna write a packet to the card .. non-blocking
  727. */
  728. int
  729. isdn_ppp_write(int min, struct file *file, const char __user *buf, int count)
  730. {
  731. isdn_net_local *lp;
  732. struct ippp_struct *is;
  733. int proto;
  734. is = file->private_data;
  735. if (!(is->state & IPPP_CONNECT))
  736. return 0;
  737. lp = is->lp;
  738. /* -> push it directly to the lowlevel interface */
  739. if (!lp)
  740. printk(KERN_DEBUG "isdn_ppp_write: lp == NULL\n");
  741. else {
  742. if (lp->isdn_device < 0 || lp->isdn_channel < 0) {
  743. unsigned char protobuf[4];
  744. /*
  745. * Don't reset huptimer for
  746. * LCP packets. (Echo requests).
  747. */
  748. if (copy_from_user(protobuf, buf, 4))
  749. return -EFAULT;
  750. proto = PPP_PROTOCOL(protobuf);
  751. if (proto != PPP_LCP)
  752. lp->huptimer = 0;
  753. return 0;
  754. }
  755. if ((dev->drv[lp->isdn_device]->flags & DRV_FLAG_RUNNING) &&
  756. lp->dialstate == 0 &&
  757. (lp->flags & ISDN_NET_CONNECTED)) {
  758. unsigned short hl;
  759. struct sk_buff *skb;
  760. unsigned char *cpy_buf;
  761. /*
  762. * we need to reserve enough space in front of
  763. * sk_buff. old call to dev_alloc_skb only reserved
  764. * 16 bytes, now we are looking what the driver want
  765. */
  766. hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
  767. skb = alloc_skb(hl + count, GFP_ATOMIC);
  768. if (!skb) {
  769. printk(KERN_WARNING "isdn_ppp_write: out of memory!\n");
  770. return count;
  771. }
  772. skb_reserve(skb, hl);
  773. cpy_buf = skb_put(skb, count);
  774. if (copy_from_user(cpy_buf, buf, count))
  775. {
  776. kfree_skb(skb);
  777. return -EFAULT;
  778. }
  779. /*
  780. * Don't reset huptimer for
  781. * LCP packets. (Echo requests).
  782. */
  783. proto = PPP_PROTOCOL(cpy_buf);
  784. if (proto != PPP_LCP)
  785. lp->huptimer = 0;
  786. if (is->debug & 0x40) {
  787. printk(KERN_DEBUG "ppp xmit: len %d\n", (int) skb->len);
  788. isdn_ppp_frame_log("xmit", skb->data, skb->len, 32, is->unit, lp->ppp_slot);
  789. }
  790. isdn_ppp_send_ccp(lp->netdev, lp, skb); /* keeps CCP/compression states in sync */
  791. isdn_net_write_super(lp, skb);
  792. }
  793. }
  794. return count;
  795. }
  796. /*
  797. * init memory, structures etc.
  798. */
  799. int
  800. isdn_ppp_init(void)
  801. {
  802. int i,
  803. j;
  804. #ifdef CONFIG_ISDN_MPP
  805. if (isdn_ppp_mp_bundle_array_init() < 0)
  806. return -ENOMEM;
  807. #endif /* CONFIG_ISDN_MPP */
  808. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  809. if (!(ippp_table[i] = kzalloc(sizeof(struct ippp_struct), GFP_KERNEL))) {
  810. printk(KERN_WARNING "isdn_ppp_init: Could not alloc ippp_table\n");
  811. for (j = 0; j < i; j++)
  812. kfree(ippp_table[j]);
  813. return -1;
  814. }
  815. spin_lock_init(&ippp_table[i]->buflock);
  816. ippp_table[i]->state = 0;
  817. ippp_table[i]->first = ippp_table[i]->rq + NUM_RCV_BUFFS - 1;
  818. ippp_table[i]->last = ippp_table[i]->rq;
  819. for (j = 0; j < NUM_RCV_BUFFS; j++) {
  820. ippp_table[i]->rq[j].buf = NULL;
  821. ippp_table[i]->rq[j].last = ippp_table[i]->rq +
  822. (NUM_RCV_BUFFS + j - 1) % NUM_RCV_BUFFS;
  823. ippp_table[i]->rq[j].next = ippp_table[i]->rq + (j + 1) % NUM_RCV_BUFFS;
  824. }
  825. }
  826. return 0;
  827. }
  828. void
  829. isdn_ppp_cleanup(void)
  830. {
  831. int i;
  832. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  833. kfree(ippp_table[i]);
  834. #ifdef CONFIG_ISDN_MPP
  835. kfree(isdn_ppp_bundle_arr);
  836. #endif /* CONFIG_ISDN_MPP */
  837. }
  838. /*
  839. * check for address/control field and skip if allowed
  840. * retval != 0 -> discard packet silently
  841. */
  842. static int isdn_ppp_skip_ac(struct ippp_struct *is, struct sk_buff *skb)
  843. {
  844. if (skb->len < 1)
  845. return -1;
  846. if (skb->data[0] == 0xff) {
  847. if (skb->len < 2)
  848. return -1;
  849. if (skb->data[1] != 0x03)
  850. return -1;
  851. // skip address/control (AC) field
  852. skb_pull(skb, 2);
  853. } else {
  854. if (is->pppcfg & SC_REJ_COMP_AC)
  855. // if AC compression was not negotiated, but used, discard packet
  856. return -1;
  857. }
  858. return 0;
  859. }
  860. /*
  861. * get the PPP protocol header and pull skb
  862. * retval < 0 -> discard packet silently
  863. */
  864. static int isdn_ppp_strip_proto(struct sk_buff *skb)
  865. {
  866. int proto;
  867. if (skb->len < 1)
  868. return -1;
  869. if (skb->data[0] & 0x1) {
  870. // protocol field is compressed
  871. proto = skb->data[0];
  872. skb_pull(skb, 1);
  873. } else {
  874. if (skb->len < 2)
  875. return -1;
  876. proto = ((int) skb->data[0] << 8) + skb->data[1];
  877. skb_pull(skb, 2);
  878. }
  879. return proto;
  880. }
  881. /*
  882. * handler for incoming packets on a syncPPP interface
  883. */
  884. void isdn_ppp_receive(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *skb)
  885. {
  886. struct ippp_struct *is;
  887. int slot;
  888. int proto;
  889. BUG_ON(net_dev->local->master); // we're called with the master device always
  890. slot = lp->ppp_slot;
  891. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  892. printk(KERN_ERR "isdn_ppp_receive: lp->ppp_slot(%d)\n",
  893. lp->ppp_slot);
  894. kfree_skb(skb);
  895. return;
  896. }
  897. is = ippp_table[slot];
  898. if (is->debug & 0x4) {
  899. printk(KERN_DEBUG "ippp_receive: is:%08lx lp:%08lx slot:%d unit:%d len:%d\n",
  900. (long)is, (long)lp, lp->ppp_slot, is->unit, (int)skb->len);
  901. isdn_ppp_frame_log("receive", skb->data, skb->len, 32, is->unit, lp->ppp_slot);
  902. }
  903. if (isdn_ppp_skip_ac(is, skb) < 0) {
  904. kfree_skb(skb);
  905. return;
  906. }
  907. proto = isdn_ppp_strip_proto(skb);
  908. if (proto < 0) {
  909. kfree_skb(skb);
  910. return;
  911. }
  912. #ifdef CONFIG_ISDN_MPP
  913. if (is->compflags & SC_LINK_DECOMP_ON) {
  914. skb = isdn_ppp_decompress(skb, is, NULL, &proto);
  915. if (!skb) // decompression error
  916. return;
  917. }
  918. if (!(is->mpppcfg & SC_REJ_MP_PROT)) { // we agreed to receive MPPP
  919. if (proto == PPP_MP) {
  920. isdn_ppp_mp_receive(net_dev, lp, skb);
  921. return;
  922. }
  923. }
  924. #endif
  925. isdn_ppp_push_higher(net_dev, lp, skb, proto);
  926. }
  927. /*
  928. * we receive a reassembled frame, MPPP has been taken care of before.
  929. * address/control and protocol have been stripped from the skb
  930. * note: net_dev has to be master net_dev
  931. */
  932. static void
  933. isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *skb, int proto)
  934. {
  935. struct net_device *dev = net_dev->dev;
  936. struct ippp_struct *is, *mis;
  937. isdn_net_local *mlp = NULL;
  938. int slot;
  939. slot = lp->ppp_slot;
  940. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  941. printk(KERN_ERR "isdn_ppp_push_higher: lp->ppp_slot(%d)\n",
  942. lp->ppp_slot);
  943. goto drop_packet;
  944. }
  945. is = ippp_table[slot];
  946. if (lp->master) { // FIXME?
  947. mlp = ISDN_MASTER_PRIV(lp);
  948. slot = mlp->ppp_slot;
  949. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  950. printk(KERN_ERR "isdn_ppp_push_higher: master->ppp_slot(%d)\n",
  951. lp->ppp_slot);
  952. goto drop_packet;
  953. }
  954. }
  955. mis = ippp_table[slot];
  956. if (is->debug & 0x10) {
  957. printk(KERN_DEBUG "push, skb %d %04x\n", (int) skb->len, proto);
  958. isdn_ppp_frame_log("rpush", skb->data, skb->len, 32, is->unit, lp->ppp_slot);
  959. }
  960. if (mis->compflags & SC_DECOMP_ON) {
  961. skb = isdn_ppp_decompress(skb, is, mis, &proto);
  962. if (!skb) // decompression error
  963. return;
  964. }
  965. switch (proto) {
  966. case PPP_IPX: /* untested */
  967. if (is->debug & 0x20)
  968. printk(KERN_DEBUG "isdn_ppp: IPX\n");
  969. skb->protocol = htons(ETH_P_IPX);
  970. break;
  971. case PPP_IP:
  972. if (is->debug & 0x20)
  973. printk(KERN_DEBUG "isdn_ppp: IP\n");
  974. skb->protocol = htons(ETH_P_IP);
  975. break;
  976. case PPP_COMP:
  977. case PPP_COMPFRAG:
  978. printk(KERN_INFO "isdn_ppp: unexpected compressed frame dropped\n");
  979. goto drop_packet;
  980. #ifdef CONFIG_ISDN_PPP_VJ
  981. case PPP_VJC_UNCOMP:
  982. if (is->debug & 0x20)
  983. printk(KERN_DEBUG "isdn_ppp: VJC_UNCOMP\n");
  984. if (net_dev->local->ppp_slot < 0) {
  985. printk(KERN_ERR "%s: net_dev->local->ppp_slot(%d) out of range\n",
  986. __func__, net_dev->local->ppp_slot);
  987. goto drop_packet;
  988. }
  989. if (slhc_remember(ippp_table[net_dev->local->ppp_slot]->slcomp, skb->data, skb->len) <= 0) {
  990. printk(KERN_WARNING "isdn_ppp: received illegal VJC_UNCOMP frame!\n");
  991. goto drop_packet;
  992. }
  993. skb->protocol = htons(ETH_P_IP);
  994. break;
  995. case PPP_VJC_COMP:
  996. if (is->debug & 0x20)
  997. printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
  998. {
  999. struct sk_buff *skb_old = skb;
  1000. int pkt_len;
  1001. skb = dev_alloc_skb(skb_old->len + 128);
  1002. if (!skb) {
  1003. printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
  1004. skb = skb_old;
  1005. goto drop_packet;
  1006. }
  1007. skb_put(skb, skb_old->len + 128);
  1008. skb_copy_from_linear_data(skb_old, skb->data,
  1009. skb_old->len);
  1010. if (net_dev->local->ppp_slot < 0) {
  1011. printk(KERN_ERR "%s: net_dev->local->ppp_slot(%d) out of range\n",
  1012. __func__, net_dev->local->ppp_slot);
  1013. goto drop_packet;
  1014. }
  1015. pkt_len = slhc_uncompress(ippp_table[net_dev->local->ppp_slot]->slcomp,
  1016. skb->data, skb_old->len);
  1017. kfree_skb(skb_old);
  1018. if (pkt_len < 0)
  1019. goto drop_packet;
  1020. skb_trim(skb, pkt_len);
  1021. skb->protocol = htons(ETH_P_IP);
  1022. }
  1023. break;
  1024. #endif
  1025. case PPP_CCP:
  1026. case PPP_CCPFRAG:
  1027. isdn_ppp_receive_ccp(net_dev, lp, skb, proto);
  1028. /* Dont pop up ResetReq/Ack stuff to the daemon any
  1029. longer - the job is done already */
  1030. if (skb->data[0] == CCP_RESETREQ ||
  1031. skb->data[0] == CCP_RESETACK)
  1032. break;
  1033. /* fall through */
  1034. default:
  1035. isdn_ppp_fill_rq(skb->data, skb->len, proto, lp->ppp_slot); /* push data to pppd device */
  1036. kfree_skb(skb);
  1037. return;
  1038. }
  1039. #ifdef CONFIG_IPPP_FILTER
  1040. /* check if the packet passes the pass and active filters
  1041. * the filter instructions are constructed assuming
  1042. * a four-byte PPP header on each packet (which is still present) */
  1043. skb_push(skb, 4);
  1044. {
  1045. u_int16_t *p = (u_int16_t *) skb->data;
  1046. *p = 0; /* indicate inbound */
  1047. }
  1048. if (is->pass_filter
  1049. && BPF_PROG_RUN(is->pass_filter, skb) == 0) {
  1050. if (is->debug & 0x2)
  1051. printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
  1052. kfree_skb(skb);
  1053. return;
  1054. }
  1055. if (!(is->active_filter
  1056. && BPF_PROG_RUN(is->active_filter, skb) == 0)) {
  1057. if (is->debug & 0x2)
  1058. printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
  1059. lp->huptimer = 0;
  1060. if (mlp)
  1061. mlp->huptimer = 0;
  1062. }
  1063. skb_pull(skb, 4);
  1064. #else /* CONFIG_IPPP_FILTER */
  1065. lp->huptimer = 0;
  1066. if (mlp)
  1067. mlp->huptimer = 0;
  1068. #endif /* CONFIG_IPPP_FILTER */
  1069. skb->dev = dev;
  1070. skb_reset_mac_header(skb);
  1071. netif_rx(skb);
  1072. /* net_dev->local->stats.rx_packets++; done in isdn_net.c */
  1073. return;
  1074. drop_packet:
  1075. net_dev->local->stats.rx_dropped++;
  1076. kfree_skb(skb);
  1077. }
  1078. /*
  1079. * isdn_ppp_skb_push ..
  1080. * checks whether we have enough space at the beginning of the skb
  1081. * and allocs a new SKB if necessary
  1082. */
  1083. static unsigned char *isdn_ppp_skb_push(struct sk_buff **skb_p, int len)
  1084. {
  1085. struct sk_buff *skb = *skb_p;
  1086. if (skb_headroom(skb) < len) {
  1087. struct sk_buff *nskb = skb_realloc_headroom(skb, len);
  1088. if (!nskb) {
  1089. printk(KERN_ERR "isdn_ppp_skb_push: can't realloc headroom!\n");
  1090. dev_kfree_skb(skb);
  1091. return NULL;
  1092. }
  1093. printk(KERN_DEBUG "isdn_ppp_skb_push:under %d %d\n", skb_headroom(skb), len);
  1094. dev_kfree_skb(skb);
  1095. *skb_p = nskb;
  1096. return skb_push(nskb, len);
  1097. }
  1098. return skb_push(skb, len);
  1099. }
  1100. /*
  1101. * send ppp frame .. we expect a PIDCOMPressable proto --
  1102. * (here: currently always PPP_IP,PPP_VJC_COMP,PPP_VJC_UNCOMP)
  1103. *
  1104. * VJ compression may change skb pointer!!! .. requeue with old
  1105. * skb isn't allowed!!
  1106. */
  1107. int
  1108. isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
  1109. {
  1110. isdn_net_local *lp, *mlp;
  1111. isdn_net_dev *nd;
  1112. unsigned int proto = PPP_IP; /* 0x21 */
  1113. struct ippp_struct *ipt, *ipts;
  1114. int slot, retval = NETDEV_TX_OK;
  1115. mlp = netdev_priv(netdev);
  1116. nd = mlp->netdev; /* get master lp */
  1117. slot = mlp->ppp_slot;
  1118. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1119. printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n",
  1120. mlp->ppp_slot);
  1121. kfree_skb(skb);
  1122. goto out;
  1123. }
  1124. ipts = ippp_table[slot];
  1125. if (!(ipts->pppcfg & SC_ENABLE_IP)) { /* PPP connected ? */
  1126. if (ipts->debug & 0x1)
  1127. printk(KERN_INFO "%s: IP frame delayed.\n", netdev->name);
  1128. retval = NETDEV_TX_BUSY;
  1129. goto out;
  1130. }
  1131. switch (ntohs(skb->protocol)) {
  1132. case ETH_P_IP:
  1133. proto = PPP_IP;
  1134. break;
  1135. case ETH_P_IPX:
  1136. proto = PPP_IPX; /* untested */
  1137. break;
  1138. default:
  1139. printk(KERN_ERR "isdn_ppp: skipped unsupported protocol: %#x.\n",
  1140. skb->protocol);
  1141. dev_kfree_skb(skb);
  1142. goto out;
  1143. }
  1144. lp = isdn_net_get_locked_lp(nd);
  1145. if (!lp) {
  1146. printk(KERN_WARNING "%s: all channels busy - requeuing!\n", netdev->name);
  1147. retval = NETDEV_TX_BUSY;
  1148. goto out;
  1149. }
  1150. /* we have our lp locked from now on */
  1151. slot = lp->ppp_slot;
  1152. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1153. printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n",
  1154. lp->ppp_slot);
  1155. kfree_skb(skb);
  1156. goto unlock;
  1157. }
  1158. ipt = ippp_table[slot];
  1159. /*
  1160. * after this line .. requeueing in the device queue is no longer allowed!!!
  1161. */
  1162. /* Pull off the fake header we stuck on earlier to keep
  1163. * the fragmentation code happy.
  1164. */
  1165. skb_pull(skb, IPPP_MAX_HEADER);
  1166. #ifdef CONFIG_IPPP_FILTER
  1167. /* check if we should pass this packet
  1168. * the filter instructions are constructed assuming
  1169. * a four-byte PPP header on each packet */
  1170. *skb_push(skb, 4) = 1; /* indicate outbound */
  1171. {
  1172. __be16 *p = (__be16 *)skb->data;
  1173. p++;
  1174. *p = htons(proto);
  1175. }
  1176. if (ipt->pass_filter
  1177. && BPF_PROG_RUN(ipt->pass_filter, skb) == 0) {
  1178. if (ipt->debug & 0x4)
  1179. printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
  1180. kfree_skb(skb);
  1181. goto unlock;
  1182. }
  1183. if (!(ipt->active_filter
  1184. && BPF_PROG_RUN(ipt->active_filter, skb) == 0)) {
  1185. if (ipt->debug & 0x4)
  1186. printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
  1187. lp->huptimer = 0;
  1188. }
  1189. skb_pull(skb, 4);
  1190. #else /* CONFIG_IPPP_FILTER */
  1191. lp->huptimer = 0;
  1192. #endif /* CONFIG_IPPP_FILTER */
  1193. if (ipt->debug & 0x4)
  1194. printk(KERN_DEBUG "xmit skb, len %d\n", (int) skb->len);
  1195. if (ipts->debug & 0x40)
  1196. isdn_ppp_frame_log("xmit0", skb->data, skb->len, 32, ipts->unit, lp->ppp_slot);
  1197. #ifdef CONFIG_ISDN_PPP_VJ
  1198. if (proto == PPP_IP && ipts->pppcfg & SC_COMP_TCP) { /* ipts here? probably yes, but check this again */
  1199. struct sk_buff *new_skb;
  1200. unsigned short hl;
  1201. /*
  1202. * we need to reserve enough space in front of
  1203. * sk_buff. old call to dev_alloc_skb only reserved
  1204. * 16 bytes, now we are looking what the driver want.
  1205. */
  1206. hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen + IPPP_MAX_HEADER;
  1207. /*
  1208. * Note: hl might still be insufficient because the method
  1209. * above does not account for a possibible MPPP slave channel
  1210. * which had larger HL header space requirements than the
  1211. * master.
  1212. */
  1213. new_skb = alloc_skb(hl + skb->len, GFP_ATOMIC);
  1214. if (new_skb) {
  1215. u_char *buf;
  1216. int pktlen;
  1217. skb_reserve(new_skb, hl);
  1218. new_skb->dev = skb->dev;
  1219. skb_put(new_skb, skb->len);
  1220. buf = skb->data;
  1221. pktlen = slhc_compress(ipts->slcomp, skb->data, skb->len, new_skb->data,
  1222. &buf, !(ipts->pppcfg & SC_NO_TCP_CCID));
  1223. if (buf != skb->data) {
  1224. if (new_skb->data != buf)
  1225. printk(KERN_ERR "isdn_ppp: FATAL error after slhc_compress!!\n");
  1226. dev_kfree_skb(skb);
  1227. skb = new_skb;
  1228. } else {
  1229. dev_kfree_skb(new_skb);
  1230. }
  1231. skb_trim(skb, pktlen);
  1232. if (skb->data[0] & SL_TYPE_COMPRESSED_TCP) { /* cslip? style -> PPP */
  1233. proto = PPP_VJC_COMP;
  1234. skb->data[0] ^= SL_TYPE_COMPRESSED_TCP;
  1235. } else {
  1236. if (skb->data[0] >= SL_TYPE_UNCOMPRESSED_TCP)
  1237. proto = PPP_VJC_UNCOMP;
  1238. skb->data[0] = (skb->data[0] & 0x0f) | 0x40;
  1239. }
  1240. }
  1241. }
  1242. #endif
  1243. /*
  1244. * normal (single link) or bundle compression
  1245. */
  1246. if (ipts->compflags & SC_COMP_ON) {
  1247. /* We send compressed only if both down- und upstream
  1248. compression is negotiated, that means, CCP is up */
  1249. if (ipts->compflags & SC_DECOMP_ON) {
  1250. skb = isdn_ppp_compress(skb, &proto, ipt, ipts, 0);
  1251. } else {
  1252. printk(KERN_DEBUG "isdn_ppp: CCP not yet up - sending as-is\n");
  1253. }
  1254. }
  1255. if (ipt->debug & 0x24)
  1256. printk(KERN_DEBUG "xmit2 skb, len %d, proto %04x\n", (int) skb->len, proto);
  1257. #ifdef CONFIG_ISDN_MPP
  1258. if (ipt->mpppcfg & SC_MP_PROT) {
  1259. /* we get mp_seqno from static isdn_net_local */
  1260. long mp_seqno = ipts->mp_seqno;
  1261. ipts->mp_seqno++;
  1262. if (ipt->mpppcfg & SC_OUT_SHORT_SEQ) {
  1263. unsigned char *data = isdn_ppp_skb_push(&skb, 3);
  1264. if (!data)
  1265. goto unlock;
  1266. mp_seqno &= 0xfff;
  1267. data[0] = MP_BEGIN_FRAG | MP_END_FRAG | ((mp_seqno >> 8) & 0xf); /* (B)egin & (E)ndbit .. */
  1268. data[1] = mp_seqno & 0xff;
  1269. data[2] = proto; /* PID compression */
  1270. } else {
  1271. unsigned char *data = isdn_ppp_skb_push(&skb, 5);
  1272. if (!data)
  1273. goto unlock;
  1274. data[0] = MP_BEGIN_FRAG | MP_END_FRAG; /* (B)egin & (E)ndbit .. */
  1275. data[1] = (mp_seqno >> 16) & 0xff; /* sequence number: 24bit */
  1276. data[2] = (mp_seqno >> 8) & 0xff;
  1277. data[3] = (mp_seqno >> 0) & 0xff;
  1278. data[4] = proto; /* PID compression */
  1279. }
  1280. proto = PPP_MP; /* MP Protocol, 0x003d */
  1281. }
  1282. #endif
  1283. /*
  1284. * 'link in bundle' compression ...
  1285. */
  1286. if (ipt->compflags & SC_LINK_COMP_ON)
  1287. skb = isdn_ppp_compress(skb, &proto, ipt, ipts, 1);
  1288. if ((ipt->pppcfg & SC_COMP_PROT) && (proto <= 0xff)) {
  1289. unsigned char *data = isdn_ppp_skb_push(&skb, 1);
  1290. if (!data)
  1291. goto unlock;
  1292. data[0] = proto & 0xff;
  1293. }
  1294. else {
  1295. unsigned char *data = isdn_ppp_skb_push(&skb, 2);
  1296. if (!data)
  1297. goto unlock;
  1298. data[0] = (proto >> 8) & 0xff;
  1299. data[1] = proto & 0xff;
  1300. }
  1301. if (!(ipt->pppcfg & SC_COMP_AC)) {
  1302. unsigned char *data = isdn_ppp_skb_push(&skb, 2);
  1303. if (!data)
  1304. goto unlock;
  1305. data[0] = 0xff; /* All Stations */
  1306. data[1] = 0x03; /* Unnumbered information */
  1307. }
  1308. /* tx-stats are now updated via BSENT-callback */
  1309. if (ipts->debug & 0x40) {
  1310. printk(KERN_DEBUG "skb xmit: len: %d\n", (int) skb->len);
  1311. isdn_ppp_frame_log("xmit", skb->data, skb->len, 32, ipt->unit, lp->ppp_slot);
  1312. }
  1313. isdn_net_writebuf_skb(lp, skb);
  1314. unlock:
  1315. spin_unlock_bh(&lp->xmit_lock);
  1316. out:
  1317. return retval;
  1318. }
  1319. #ifdef CONFIG_IPPP_FILTER
  1320. /*
  1321. * check if this packet may trigger auto-dial.
  1322. */
  1323. int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
  1324. {
  1325. struct ippp_struct *is = ippp_table[lp->ppp_slot];
  1326. u_int16_t proto;
  1327. int drop = 0;
  1328. switch (ntohs(skb->protocol)) {
  1329. case ETH_P_IP:
  1330. proto = PPP_IP;
  1331. break;
  1332. case ETH_P_IPX:
  1333. proto = PPP_IPX;
  1334. break;
  1335. default:
  1336. printk(KERN_ERR "isdn_ppp_autodial_filter: unsupported protocol 0x%x.\n",
  1337. skb->protocol);
  1338. return 1;
  1339. }
  1340. /* the filter instructions are constructed assuming
  1341. * a four-byte PPP header on each packet. we have to
  1342. * temporarily remove part of the fake header stuck on
  1343. * earlier.
  1344. */
  1345. *skb_pull(skb, IPPP_MAX_HEADER - 4) = 1; /* indicate outbound */
  1346. {
  1347. __be16 *p = (__be16 *)skb->data;
  1348. p++;
  1349. *p = htons(proto);
  1350. }
  1351. drop |= is->pass_filter
  1352. && BPF_PROG_RUN(is->pass_filter, skb) == 0;
  1353. drop |= is->active_filter
  1354. && BPF_PROG_RUN(is->active_filter, skb) == 0;
  1355. skb_push(skb, IPPP_MAX_HEADER - 4);
  1356. return drop;
  1357. }
  1358. #endif
  1359. #ifdef CONFIG_ISDN_MPP
  1360. /* this is _not_ rfc1990 header, but something we convert both short and long
  1361. * headers to for convinience's sake:
  1362. * byte 0 is flags as in rfc1990
  1363. * bytes 1...4 is 24-bit seqence number converted to host byte order
  1364. */
  1365. #define MP_HEADER_LEN 5
  1366. #define MP_LONGSEQ_MASK 0x00ffffff
  1367. #define MP_SHORTSEQ_MASK 0x00000fff
  1368. #define MP_LONGSEQ_MAX MP_LONGSEQ_MASK
  1369. #define MP_SHORTSEQ_MAX MP_SHORTSEQ_MASK
  1370. #define MP_LONGSEQ_MAXBIT ((MP_LONGSEQ_MASK + 1) >> 1)
  1371. #define MP_SHORTSEQ_MAXBIT ((MP_SHORTSEQ_MASK + 1) >> 1)
  1372. /* sequence-wrap safe comparisons (for long sequence)*/
  1373. #define MP_LT(a, b) ((a - b) & MP_LONGSEQ_MAXBIT)
  1374. #define MP_LE(a, b) !((b - a) & MP_LONGSEQ_MAXBIT)
  1375. #define MP_GT(a, b) ((b - a) & MP_LONGSEQ_MAXBIT)
  1376. #define MP_GE(a, b) !((a - b) & MP_LONGSEQ_MAXBIT)
  1377. #define MP_SEQ(f) ((*(u32 *)(f->data + 1)))
  1378. #define MP_FLAGS(f) (f->data[0])
  1379. static int isdn_ppp_mp_bundle_array_init(void)
  1380. {
  1381. int i;
  1382. int sz = ISDN_MAX_CHANNELS * sizeof(ippp_bundle);
  1383. if ((isdn_ppp_bundle_arr = kzalloc(sz, GFP_KERNEL)) == NULL)
  1384. return -ENOMEM;
  1385. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1386. spin_lock_init(&isdn_ppp_bundle_arr[i].lock);
  1387. return 0;
  1388. }
  1389. static ippp_bundle *isdn_ppp_mp_bundle_alloc(void)
  1390. {
  1391. int i;
  1392. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1393. if (isdn_ppp_bundle_arr[i].ref_ct <= 0)
  1394. return (isdn_ppp_bundle_arr + i);
  1395. return NULL;
  1396. }
  1397. static int isdn_ppp_mp_init(isdn_net_local *lp, ippp_bundle *add_to)
  1398. {
  1399. struct ippp_struct *is;
  1400. if (lp->ppp_slot < 0) {
  1401. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  1402. __func__, lp->ppp_slot);
  1403. return (-EINVAL);
  1404. }
  1405. is = ippp_table[lp->ppp_slot];
  1406. if (add_to) {
  1407. if (lp->netdev->pb)
  1408. lp->netdev->pb->ref_ct--;
  1409. lp->netdev->pb = add_to;
  1410. } else { /* first link in a bundle */
  1411. is->mp_seqno = 0;
  1412. if ((lp->netdev->pb = isdn_ppp_mp_bundle_alloc()) == NULL)
  1413. return -ENOMEM;
  1414. lp->next = lp->last = lp; /* nobody else in a queue */
  1415. lp->netdev->pb->frags = NULL;
  1416. lp->netdev->pb->frames = 0;
  1417. lp->netdev->pb->seq = UINT_MAX;
  1418. }
  1419. lp->netdev->pb->ref_ct++;
  1420. is->last_link_seqno = 0;
  1421. return 0;
  1422. }
  1423. static u32 isdn_ppp_mp_get_seq(int short_seq,
  1424. struct sk_buff *skb, u32 last_seq);
  1425. static struct sk_buff *isdn_ppp_mp_discard(ippp_bundle *mp,
  1426. struct sk_buff *from, struct sk_buff *to);
  1427. static void isdn_ppp_mp_reassembly(isdn_net_dev *net_dev, isdn_net_local *lp,
  1428. struct sk_buff *from, struct sk_buff *to);
  1429. static void isdn_ppp_mp_free_skb(ippp_bundle *mp, struct sk_buff *skb);
  1430. static void isdn_ppp_mp_print_recv_pkt(int slot, struct sk_buff *skb);
  1431. static void isdn_ppp_mp_receive(isdn_net_dev *net_dev, isdn_net_local *lp,
  1432. struct sk_buff *skb)
  1433. {
  1434. struct ippp_struct *is;
  1435. isdn_net_local *lpq;
  1436. ippp_bundle *mp;
  1437. isdn_mppp_stats *stats;
  1438. struct sk_buff *newfrag, *frag, *start, *nextf;
  1439. u32 newseq, minseq, thisseq;
  1440. unsigned long flags;
  1441. int slot;
  1442. spin_lock_irqsave(&net_dev->pb->lock, flags);
  1443. mp = net_dev->pb;
  1444. stats = &mp->stats;
  1445. slot = lp->ppp_slot;
  1446. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1447. printk(KERN_ERR "%s: lp->ppp_slot(%d)\n",
  1448. __func__, lp->ppp_slot);
  1449. stats->frame_drops++;
  1450. dev_kfree_skb(skb);
  1451. spin_unlock_irqrestore(&mp->lock, flags);
  1452. return;
  1453. }
  1454. is = ippp_table[slot];
  1455. if (++mp->frames > stats->max_queue_len)
  1456. stats->max_queue_len = mp->frames;
  1457. if (is->debug & 0x8)
  1458. isdn_ppp_mp_print_recv_pkt(lp->ppp_slot, skb);
  1459. newseq = isdn_ppp_mp_get_seq(is->mpppcfg & SC_IN_SHORT_SEQ,
  1460. skb, is->last_link_seqno);
  1461. /* if this packet seq # is less than last already processed one,
  1462. * toss it right away, but check for sequence start case first
  1463. */
  1464. if (mp->seq > MP_LONGSEQ_MAX && (newseq & MP_LONGSEQ_MAXBIT)) {
  1465. mp->seq = newseq; /* the first packet: required for
  1466. * rfc1990 non-compliant clients --
  1467. * prevents constant packet toss */
  1468. } else if (MP_LT(newseq, mp->seq)) {
  1469. stats->frame_drops++;
  1470. isdn_ppp_mp_free_skb(mp, skb);
  1471. spin_unlock_irqrestore(&mp->lock, flags);
  1472. return;
  1473. }
  1474. /* find the minimum received sequence number over all links */
  1475. is->last_link_seqno = minseq = newseq;
  1476. for (lpq = net_dev->queue;;) {
  1477. slot = lpq->ppp_slot;
  1478. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  1479. printk(KERN_ERR "%s: lpq->ppp_slot(%d)\n",
  1480. __func__, lpq->ppp_slot);
  1481. } else {
  1482. u32 lls = ippp_table[slot]->last_link_seqno;
  1483. if (MP_LT(lls, minseq))
  1484. minseq = lls;
  1485. }
  1486. if ((lpq = lpq->next) == net_dev->queue)
  1487. break;
  1488. }
  1489. if (MP_LT(minseq, mp->seq))
  1490. minseq = mp->seq; /* can't go beyond already processed
  1491. * packets */
  1492. newfrag = skb;
  1493. /* if this new fragment is before the first one, then enqueue it now. */
  1494. if ((frag = mp->frags) == NULL || MP_LT(newseq, MP_SEQ(frag))) {
  1495. newfrag->next = frag;
  1496. mp->frags = frag = newfrag;
  1497. newfrag = NULL;
  1498. }
  1499. start = MP_FLAGS(frag) & MP_BEGIN_FRAG &&
  1500. MP_SEQ(frag) == mp->seq ? frag : NULL;
  1501. /*
  1502. * main fragment traversing loop
  1503. *
  1504. * try to accomplish several tasks:
  1505. * - insert new fragment into the proper sequence slot (once that's done
  1506. * newfrag will be set to NULL)
  1507. * - reassemble any complete fragment sequence (non-null 'start'
  1508. * indicates there is a contiguous sequence present)
  1509. * - discard any incomplete sequences that are below minseq -- due
  1510. * to the fact that sender always increment sequence number, if there
  1511. * is an incomplete sequence below minseq, no new fragments would
  1512. * come to complete such sequence and it should be discarded
  1513. *
  1514. * loop completes when we accomplished the following tasks:
  1515. * - new fragment is inserted in the proper sequence ('newfrag' is
  1516. * set to NULL)
  1517. * - we hit a gap in the sequence, so no reassembly/processing is
  1518. * possible ('start' would be set to NULL)
  1519. *
  1520. * algorithm for this code is derived from code in the book
  1521. * 'PPP Design And Debugging' by James Carlson (Addison-Wesley)
  1522. */
  1523. while (start != NULL || newfrag != NULL) {
  1524. thisseq = MP_SEQ(frag);
  1525. nextf = frag->next;
  1526. /* drop any duplicate fragments */
  1527. if (newfrag != NULL && thisseq == newseq) {
  1528. isdn_ppp_mp_free_skb(mp, newfrag);
  1529. newfrag = NULL;
  1530. }
  1531. /* insert new fragment before next element if possible. */
  1532. if (newfrag != NULL && (nextf == NULL ||
  1533. MP_LT(newseq, MP_SEQ(nextf)))) {
  1534. newfrag->next = nextf;
  1535. frag->next = nextf = newfrag;
  1536. newfrag = NULL;
  1537. }
  1538. if (start != NULL) {
  1539. /* check for misplaced start */
  1540. if (start != frag && (MP_FLAGS(frag) & MP_BEGIN_FRAG)) {
  1541. printk(KERN_WARNING"isdn_mppp(seq %d): new "
  1542. "BEGIN flag with no prior END", thisseq);
  1543. stats->seqerrs++;
  1544. stats->frame_drops++;
  1545. start = isdn_ppp_mp_discard(mp, start, frag);
  1546. nextf = frag->next;
  1547. }
  1548. } else if (MP_LE(thisseq, minseq)) {
  1549. if (MP_FLAGS(frag) & MP_BEGIN_FRAG)
  1550. start = frag;
  1551. else {
  1552. if (MP_FLAGS(frag) & MP_END_FRAG)
  1553. stats->frame_drops++;
  1554. if (mp->frags == frag)
  1555. mp->frags = nextf;
  1556. isdn_ppp_mp_free_skb(mp, frag);
  1557. frag = nextf;
  1558. continue;
  1559. }
  1560. }
  1561. /* if start is non-null and we have end fragment, then
  1562. * we have full reassembly sequence -- reassemble
  1563. * and process packet now
  1564. */
  1565. if (start != NULL && (MP_FLAGS(frag) & MP_END_FRAG)) {
  1566. minseq = mp->seq = (thisseq + 1) & MP_LONGSEQ_MASK;
  1567. /* Reassemble the packet then dispatch it */
  1568. isdn_ppp_mp_reassembly(net_dev, lp, start, nextf);
  1569. start = NULL;
  1570. frag = NULL;
  1571. mp->frags = nextf;
  1572. }
  1573. /* check if need to update start pointer: if we just
  1574. * reassembled the packet and sequence is contiguous
  1575. * then next fragment should be the start of new reassembly
  1576. * if sequence is contiguous, but we haven't reassembled yet,
  1577. * keep going.
  1578. * if sequence is not contiguous, either clear everything
  1579. * below low watermark and set start to the next frag or
  1580. * clear start ptr.
  1581. */
  1582. if (nextf != NULL &&
  1583. ((thisseq + 1) & MP_LONGSEQ_MASK) == MP_SEQ(nextf)) {
  1584. /* if we just reassembled and the next one is here,
  1585. * then start another reassembly. */
  1586. if (frag == NULL) {
  1587. if (MP_FLAGS(nextf) & MP_BEGIN_FRAG)
  1588. start = nextf;
  1589. else
  1590. {
  1591. printk(KERN_WARNING"isdn_mppp(seq %d):"
  1592. " END flag with no following "
  1593. "BEGIN", thisseq);
  1594. stats->seqerrs++;
  1595. }
  1596. }
  1597. } else {
  1598. if (nextf != NULL && frag != NULL &&
  1599. MP_LT(thisseq, minseq)) {
  1600. /* we've got a break in the sequence
  1601. * and we not at the end yet
  1602. * and we did not just reassembled
  1603. *(if we did, there wouldn't be anything before)
  1604. * and we below the low watermark
  1605. * discard all the frames below low watermark
  1606. * and start over */
  1607. stats->frame_drops++;
  1608. mp->frags = isdn_ppp_mp_discard(mp, start, nextf);
  1609. }
  1610. /* break in the sequence, no reassembly */
  1611. start = NULL;
  1612. }
  1613. frag = nextf;
  1614. } /* while -- main loop */
  1615. if (mp->frags == NULL)
  1616. mp->frags = frag;
  1617. /* rather straighforward way to deal with (not very) possible
  1618. * queue overflow */
  1619. if (mp->frames > MP_MAX_QUEUE_LEN) {
  1620. stats->overflows++;
  1621. while (mp->frames > MP_MAX_QUEUE_LEN) {
  1622. frag = mp->frags->next;
  1623. isdn_ppp_mp_free_skb(mp, mp->frags);
  1624. mp->frags = frag;
  1625. }
  1626. }
  1627. spin_unlock_irqrestore(&mp->lock, flags);
  1628. }
  1629. static void isdn_ppp_mp_cleanup(isdn_net_local *lp)
  1630. {
  1631. struct sk_buff *frag = lp->netdev->pb->frags;
  1632. struct sk_buff *nextfrag;
  1633. while (frag) {
  1634. nextfrag = frag->next;
  1635. isdn_ppp_mp_free_skb(lp->netdev->pb, frag);
  1636. frag = nextfrag;
  1637. }
  1638. lp->netdev->pb->frags = NULL;
  1639. }
  1640. static u32 isdn_ppp_mp_get_seq(int short_seq,
  1641. struct sk_buff *skb, u32 last_seq)
  1642. {
  1643. u32 seq;
  1644. int flags = skb->data[0] & (MP_BEGIN_FRAG | MP_END_FRAG);
  1645. if (!short_seq)
  1646. {
  1647. seq = ntohl(*(__be32 *)skb->data) & MP_LONGSEQ_MASK;
  1648. skb_push(skb, 1);
  1649. }
  1650. else
  1651. {
  1652. /* convert 12-bit short seq number to 24-bit long one
  1653. */
  1654. seq = ntohs(*(__be16 *)skb->data) & MP_SHORTSEQ_MASK;
  1655. /* check for seqence wrap */
  1656. if (!(seq & MP_SHORTSEQ_MAXBIT) &&
  1657. (last_seq & MP_SHORTSEQ_MAXBIT) &&
  1658. (unsigned long)last_seq <= MP_LONGSEQ_MAX)
  1659. seq |= (last_seq + MP_SHORTSEQ_MAX + 1) &
  1660. (~MP_SHORTSEQ_MASK & MP_LONGSEQ_MASK);
  1661. else
  1662. seq |= last_seq & (~MP_SHORTSEQ_MASK & MP_LONGSEQ_MASK);
  1663. skb_push(skb, 3); /* put converted seqence back in skb */
  1664. }
  1665. *(u32 *)(skb->data + 1) = seq; /* put seqence back in _host_ byte
  1666. * order */
  1667. skb->data[0] = flags; /* restore flags */
  1668. return seq;
  1669. }
  1670. struct sk_buff *isdn_ppp_mp_discard(ippp_bundle *mp,
  1671. struct sk_buff *from, struct sk_buff *to)
  1672. {
  1673. if (from)
  1674. while (from != to) {
  1675. struct sk_buff *next = from->next;
  1676. isdn_ppp_mp_free_skb(mp, from);
  1677. from = next;
  1678. }
  1679. return from;
  1680. }
  1681. void isdn_ppp_mp_reassembly(isdn_net_dev *net_dev, isdn_net_local *lp,
  1682. struct sk_buff *from, struct sk_buff *to)
  1683. {
  1684. ippp_bundle *mp = net_dev->pb;
  1685. int proto;
  1686. struct sk_buff *skb;
  1687. unsigned int tot_len;
  1688. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  1689. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  1690. __func__, lp->ppp_slot);
  1691. return;
  1692. }
  1693. if (MP_FLAGS(from) == (MP_BEGIN_FRAG | MP_END_FRAG)) {
  1694. if (ippp_table[lp->ppp_slot]->debug & 0x40)
  1695. printk(KERN_DEBUG "isdn_mppp: reassembly: frame %d, "
  1696. "len %d\n", MP_SEQ(from), from->len);
  1697. skb = from;
  1698. skb_pull(skb, MP_HEADER_LEN);
  1699. mp->frames--;
  1700. } else {
  1701. struct sk_buff *frag;
  1702. int n;
  1703. for (tot_len = n = 0, frag = from; frag != to; frag = frag->next, n++)
  1704. tot_len += frag->len - MP_HEADER_LEN;
  1705. if (ippp_table[lp->ppp_slot]->debug & 0x40)
  1706. printk(KERN_DEBUG"isdn_mppp: reassembling frames %d "
  1707. "to %d, len %d\n", MP_SEQ(from),
  1708. (MP_SEQ(from) + n - 1) & MP_LONGSEQ_MASK, tot_len);
  1709. if ((skb = dev_alloc_skb(tot_len)) == NULL) {
  1710. printk(KERN_ERR "isdn_mppp: cannot allocate sk buff "
  1711. "of size %d\n", tot_len);
  1712. isdn_ppp_mp_discard(mp, from, to);
  1713. return;
  1714. }
  1715. while (from != to) {
  1716. unsigned int len = from->len - MP_HEADER_LEN;
  1717. skb_copy_from_linear_data_offset(from, MP_HEADER_LEN,
  1718. skb_put(skb, len),
  1719. len);
  1720. frag = from->next;
  1721. isdn_ppp_mp_free_skb(mp, from);
  1722. from = frag;
  1723. }
  1724. }
  1725. proto = isdn_ppp_strip_proto(skb);
  1726. isdn_ppp_push_higher(net_dev, lp, skb, proto);
  1727. }
  1728. static void isdn_ppp_mp_free_skb(ippp_bundle *mp, struct sk_buff *skb)
  1729. {
  1730. dev_kfree_skb(skb);
  1731. mp->frames--;
  1732. }
  1733. static void isdn_ppp_mp_print_recv_pkt(int slot, struct sk_buff *skb)
  1734. {
  1735. printk(KERN_DEBUG "mp_recv: %d/%d -> %02x %02x %02x %02x %02x %02x\n",
  1736. slot, (int) skb->len,
  1737. (int) skb->data[0], (int) skb->data[1], (int) skb->data[2],
  1738. (int) skb->data[3], (int) skb->data[4], (int) skb->data[5]);
  1739. }
  1740. static int
  1741. isdn_ppp_bundle(struct ippp_struct *is, int unit)
  1742. {
  1743. char ifn[IFNAMSIZ + 1];
  1744. isdn_net_dev *p;
  1745. isdn_net_local *lp, *nlp;
  1746. int rc;
  1747. unsigned long flags;
  1748. sprintf(ifn, "ippp%d", unit);
  1749. p = isdn_net_findif(ifn);
  1750. if (!p) {
  1751. printk(KERN_ERR "ippp_bundle: cannot find %s\n", ifn);
  1752. return -EINVAL;
  1753. }
  1754. spin_lock_irqsave(&p->pb->lock, flags);
  1755. nlp = is->lp;
  1756. lp = p->queue;
  1757. if (nlp->ppp_slot < 0 || nlp->ppp_slot >= ISDN_MAX_CHANNELS ||
  1758. lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  1759. printk(KERN_ERR "ippp_bundle: binding to invalid slot %d\n",
  1760. nlp->ppp_slot < 0 || nlp->ppp_slot >= ISDN_MAX_CHANNELS ?
  1761. nlp->ppp_slot : lp->ppp_slot);
  1762. rc = -EINVAL;
  1763. goto out;
  1764. }
  1765. isdn_net_add_to_bundle(p, nlp);
  1766. ippp_table[nlp->ppp_slot]->unit = ippp_table[lp->ppp_slot]->unit;
  1767. /* maybe also SC_CCP stuff */
  1768. ippp_table[nlp->ppp_slot]->pppcfg |= ippp_table[lp->ppp_slot]->pppcfg &
  1769. (SC_ENABLE_IP | SC_NO_TCP_CCID | SC_REJ_COMP_TCP);
  1770. ippp_table[nlp->ppp_slot]->mpppcfg |= ippp_table[lp->ppp_slot]->mpppcfg &
  1771. (SC_MP_PROT | SC_REJ_MP_PROT | SC_OUT_SHORT_SEQ | SC_IN_SHORT_SEQ);
  1772. rc = isdn_ppp_mp_init(nlp, p->pb);
  1773. out:
  1774. spin_unlock_irqrestore(&p->pb->lock, flags);
  1775. return rc;
  1776. }
  1777. #endif /* CONFIG_ISDN_MPP */
  1778. /*
  1779. * network device ioctl handlers
  1780. */
  1781. static int
  1782. isdn_ppp_dev_ioctl_stats(int slot, struct ifreq *ifr, struct net_device *dev)
  1783. {
  1784. struct ppp_stats __user *res = ifr->ifr_data;
  1785. struct ppp_stats t;
  1786. isdn_net_local *lp = netdev_priv(dev);
  1787. if (!access_ok(VERIFY_WRITE, res, sizeof(struct ppp_stats)))
  1788. return -EFAULT;
  1789. /* build a temporary stat struct and copy it to user space */
  1790. memset(&t, 0, sizeof(struct ppp_stats));
  1791. if (dev->flags & IFF_UP) {
  1792. t.p.ppp_ipackets = lp->stats.rx_packets;
  1793. t.p.ppp_ibytes = lp->stats.rx_bytes;
  1794. t.p.ppp_ierrors = lp->stats.rx_errors;
  1795. t.p.ppp_opackets = lp->stats.tx_packets;
  1796. t.p.ppp_obytes = lp->stats.tx_bytes;
  1797. t.p.ppp_oerrors = lp->stats.tx_errors;
  1798. #ifdef CONFIG_ISDN_PPP_VJ
  1799. if (slot >= 0 && ippp_table[slot]->slcomp) {
  1800. struct slcompress *slcomp = ippp_table[slot]->slcomp;
  1801. t.vj.vjs_packets = slcomp->sls_o_compressed + slcomp->sls_o_uncompressed;
  1802. t.vj.vjs_compressed = slcomp->sls_o_compressed;
  1803. t.vj.vjs_searches = slcomp->sls_o_searches;
  1804. t.vj.vjs_misses = slcomp->sls_o_misses;
  1805. t.vj.vjs_errorin = slcomp->sls_i_error;
  1806. t.vj.vjs_tossed = slcomp->sls_i_tossed;
  1807. t.vj.vjs_uncompressedin = slcomp->sls_i_uncompressed;
  1808. t.vj.vjs_compressedin = slcomp->sls_i_compressed;
  1809. }
  1810. #endif
  1811. }
  1812. if (copy_to_user(res, &t, sizeof(struct ppp_stats)))
  1813. return -EFAULT;
  1814. return 0;
  1815. }
  1816. int
  1817. isdn_ppp_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1818. {
  1819. int error = 0;
  1820. int len;
  1821. isdn_net_local *lp = netdev_priv(dev);
  1822. if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
  1823. return -EINVAL;
  1824. switch (cmd) {
  1825. #define PPP_VERSION "2.3.7"
  1826. case SIOCGPPPVER:
  1827. len = strlen(PPP_VERSION) + 1;
  1828. if (copy_to_user(ifr->ifr_data, PPP_VERSION, len))
  1829. error = -EFAULT;
  1830. break;
  1831. case SIOCGPPPSTATS:
  1832. error = isdn_ppp_dev_ioctl_stats(lp->ppp_slot, ifr, dev);
  1833. break;
  1834. default:
  1835. error = -EINVAL;
  1836. break;
  1837. }
  1838. return error;
  1839. }
  1840. static int
  1841. isdn_ppp_if_get_unit(char *name)
  1842. {
  1843. int len,
  1844. i,
  1845. unit = 0,
  1846. deci;
  1847. len = strlen(name);
  1848. if (strncmp("ippp", name, 4) || len > 8)
  1849. return -1;
  1850. for (i = 0, deci = 1; i < len; i++, deci *= 10) {
  1851. char a = name[len - i - 1];
  1852. if (a >= '0' && a <= '9')
  1853. unit += (a - '0') * deci;
  1854. else
  1855. break;
  1856. }
  1857. if (!i || len - i != 4)
  1858. unit = -1;
  1859. return unit;
  1860. }
  1861. int
  1862. isdn_ppp_dial_slave(char *name)
  1863. {
  1864. #ifdef CONFIG_ISDN_MPP
  1865. isdn_net_dev *ndev;
  1866. isdn_net_local *lp;
  1867. struct net_device *sdev;
  1868. if (!(ndev = isdn_net_findif(name)))
  1869. return 1;
  1870. lp = ndev->local;
  1871. if (!(lp->flags & ISDN_NET_CONNECTED))
  1872. return 5;
  1873. sdev = lp->slave;
  1874. while (sdev) {
  1875. isdn_net_local *mlp = netdev_priv(sdev);
  1876. if (!(mlp->flags & ISDN_NET_CONNECTED))
  1877. break;
  1878. sdev = mlp->slave;
  1879. }
  1880. if (!sdev)
  1881. return 2;
  1882. isdn_net_dial_req(netdev_priv(sdev));
  1883. return 0;
  1884. #else
  1885. return -1;
  1886. #endif
  1887. }
  1888. int
  1889. isdn_ppp_hangup_slave(char *name)
  1890. {
  1891. #ifdef CONFIG_ISDN_MPP
  1892. isdn_net_dev *ndev;
  1893. isdn_net_local *lp;
  1894. struct net_device *sdev;
  1895. if (!(ndev = isdn_net_findif(name)))
  1896. return 1;
  1897. lp = ndev->local;
  1898. if (!(lp->flags & ISDN_NET_CONNECTED))
  1899. return 5;
  1900. sdev = lp->slave;
  1901. while (sdev) {
  1902. isdn_net_local *mlp = netdev_priv(sdev);
  1903. if (mlp->slave) { /* find last connected link in chain */
  1904. isdn_net_local *nlp = ISDN_SLAVE_PRIV(mlp);
  1905. if (!(nlp->flags & ISDN_NET_CONNECTED))
  1906. break;
  1907. } else if (mlp->flags & ISDN_NET_CONNECTED)
  1908. break;
  1909. sdev = mlp->slave;
  1910. }
  1911. if (!sdev)
  1912. return 2;
  1913. isdn_net_hangup(sdev);
  1914. return 0;
  1915. #else
  1916. return -1;
  1917. #endif
  1918. }
  1919. /*
  1920. * PPP compression stuff
  1921. */
  1922. /* Push an empty CCP Data Frame up to the daemon to wake it up and let it
  1923. generate a CCP Reset-Request or tear down CCP altogether */
  1924. static void isdn_ppp_ccp_kickup(struct ippp_struct *is)
  1925. {
  1926. isdn_ppp_fill_rq(NULL, 0, PPP_COMP, is->lp->ppp_slot);
  1927. }
  1928. /* In-kernel handling of CCP Reset-Request and Reset-Ack is necessary,
  1929. but absolutely nontrivial. The most abstruse problem we are facing is
  1930. that the generation, reception and all the handling of timeouts and
  1931. resends including proper request id management should be entirely left
  1932. to the (de)compressor, but indeed is not covered by the current API to
  1933. the (de)compressor. The API is a prototype version from PPP where only
  1934. some (de)compressors have yet been implemented and all of them are
  1935. rather simple in their reset handling. Especially, their is only one
  1936. outstanding ResetAck at a time with all of them and ResetReq/-Acks do
  1937. not have parameters. For this very special case it was sufficient to
  1938. just return an error code from the decompressor and have a single
  1939. reset() entry to communicate all the necessary information between
  1940. the framework and the (de)compressor. Bad enough, LZS is different
  1941. (and any other compressor may be different, too). It has multiple
  1942. histories (eventually) and needs to Reset each of them independently
  1943. and thus uses multiple outstanding Acks and history numbers as an
  1944. additional parameter to Reqs/Acks.
  1945. All that makes it harder to port the reset state engine into the
  1946. kernel because it is not just the same simple one as in (i)pppd but
  1947. it must be able to pass additional parameters and have multiple out-
  1948. standing Acks. We are trying to achieve the impossible by handling
  1949. reset transactions independent by their id. The id MUST change when
  1950. the data portion changes, thus any (de)compressor who uses more than
  1951. one resettable state must provide and recognize individual ids for
  1952. each individual reset transaction. The framework itself does _only_
  1953. differentiate them by id, because it has no other semantics like the
  1954. (de)compressor might.
  1955. This looks like a major redesign of the interface would be nice,
  1956. but I don't have an idea how to do it better. */
  1957. /* Send a CCP Reset-Request or Reset-Ack directly from the kernel. This is
  1958. getting that lengthy because there is no simple "send-this-frame-out"
  1959. function above but every wrapper does a bit different. Hope I guess
  1960. correct in this hack... */
  1961. static void isdn_ppp_ccp_xmit_reset(struct ippp_struct *is, int proto,
  1962. unsigned char code, unsigned char id,
  1963. unsigned char *data, int len)
  1964. {
  1965. struct sk_buff *skb;
  1966. unsigned char *p;
  1967. int hl;
  1968. int cnt = 0;
  1969. isdn_net_local *lp = is->lp;
  1970. /* Alloc large enough skb */
  1971. hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
  1972. skb = alloc_skb(len + hl + 16, GFP_ATOMIC);
  1973. if (!skb) {
  1974. printk(KERN_WARNING
  1975. "ippp: CCP cannot send reset - out of memory\n");
  1976. return;
  1977. }
  1978. skb_reserve(skb, hl);
  1979. /* We may need to stuff an address and control field first */
  1980. if (!(is->pppcfg & SC_COMP_AC)) {
  1981. p = skb_put(skb, 2);
  1982. *p++ = 0xff;
  1983. *p++ = 0x03;
  1984. }
  1985. /* Stuff proto, code, id and length */
  1986. p = skb_put(skb, 6);
  1987. *p++ = (proto >> 8);
  1988. *p++ = (proto & 0xff);
  1989. *p++ = code;
  1990. *p++ = id;
  1991. cnt = 4 + len;
  1992. *p++ = (cnt >> 8);
  1993. *p++ = (cnt & 0xff);
  1994. /* Now stuff remaining bytes */
  1995. if (len) {
  1996. p = skb_put(skb, len);
  1997. memcpy(p, data, len);
  1998. }
  1999. /* skb is now ready for xmit */
  2000. printk(KERN_DEBUG "Sending CCP Frame:\n");
  2001. isdn_ppp_frame_log("ccp-xmit", skb->data, skb->len, 32, is->unit, lp->ppp_slot);
  2002. isdn_net_write_super(lp, skb);
  2003. }
  2004. /* Allocate the reset state vector */
  2005. static struct ippp_ccp_reset *isdn_ppp_ccp_reset_alloc(struct ippp_struct *is)
  2006. {
  2007. struct ippp_ccp_reset *r;
  2008. r = kzalloc(sizeof(struct ippp_ccp_reset), GFP_KERNEL);
  2009. if (!r) {
  2010. printk(KERN_ERR "ippp_ccp: failed to allocate reset data"
  2011. " structure - no mem\n");
  2012. return NULL;
  2013. }
  2014. printk(KERN_DEBUG "ippp_ccp: allocated reset data structure %p\n", r);
  2015. is->reset = r;
  2016. return r;
  2017. }
  2018. /* Destroy the reset state vector. Kill all pending timers first. */
  2019. static void isdn_ppp_ccp_reset_free(struct ippp_struct *is)
  2020. {
  2021. unsigned int id;
  2022. printk(KERN_DEBUG "ippp_ccp: freeing reset data structure %p\n",
  2023. is->reset);
  2024. for (id = 0; id < 256; id++) {
  2025. if (is->reset->rs[id]) {
  2026. isdn_ppp_ccp_reset_free_state(is, (unsigned char)id);
  2027. }
  2028. }
  2029. kfree(is->reset);
  2030. is->reset = NULL;
  2031. }
  2032. /* Free a given state and clear everything up for later reallocation */
  2033. static void isdn_ppp_ccp_reset_free_state(struct ippp_struct *is,
  2034. unsigned char id)
  2035. {
  2036. struct ippp_ccp_reset_state *rs;
  2037. if (is->reset->rs[id]) {
  2038. printk(KERN_DEBUG "ippp_ccp: freeing state for id %d\n", id);
  2039. rs = is->reset->rs[id];
  2040. /* Make sure the kernel will not call back later */
  2041. if (rs->ta)
  2042. del_timer(&rs->timer);
  2043. is->reset->rs[id] = NULL;
  2044. kfree(rs);
  2045. } else {
  2046. printk(KERN_WARNING "ippp_ccp: id %d is not allocated\n", id);
  2047. }
  2048. }
  2049. /* The timer callback function which is called when a ResetReq has timed out,
  2050. aka has never been answered by a ResetAck */
  2051. static void isdn_ppp_ccp_timer_callback(unsigned long closure)
  2052. {
  2053. struct ippp_ccp_reset_state *rs =
  2054. (struct ippp_ccp_reset_state *)closure;
  2055. if (!rs) {
  2056. printk(KERN_ERR "ippp_ccp: timer cb with zero closure.\n");
  2057. return;
  2058. }
  2059. if (rs->ta && rs->state == CCPResetSentReq) {
  2060. /* We are correct here */
  2061. if (!rs->expra) {
  2062. /* Hmm, there is no Ack really expected. We can clean
  2063. up the state now, it will be reallocated if the
  2064. decompressor insists on another reset */
  2065. rs->ta = 0;
  2066. isdn_ppp_ccp_reset_free_state(rs->is, rs->id);
  2067. return;
  2068. }
  2069. printk(KERN_DEBUG "ippp_ccp: CCP Reset timed out for id %d\n",
  2070. rs->id);
  2071. /* Push it again */
  2072. isdn_ppp_ccp_xmit_reset(rs->is, PPP_CCP, CCP_RESETREQ, rs->id,
  2073. rs->data, rs->dlen);
  2074. /* Restart timer */
  2075. rs->timer.expires = jiffies + HZ * 5;
  2076. add_timer(&rs->timer);
  2077. } else {
  2078. printk(KERN_WARNING "ippp_ccp: timer cb in wrong state %d\n",
  2079. rs->state);
  2080. }
  2081. }
  2082. /* Allocate a new reset transaction state */
  2083. static struct ippp_ccp_reset_state *isdn_ppp_ccp_reset_alloc_state(struct ippp_struct *is,
  2084. unsigned char id)
  2085. {
  2086. struct ippp_ccp_reset_state *rs;
  2087. if (is->reset->rs[id]) {
  2088. printk(KERN_WARNING "ippp_ccp: old state exists for id %d\n",
  2089. id);
  2090. return NULL;
  2091. } else {
  2092. rs = kzalloc(sizeof(struct ippp_ccp_reset_state), GFP_ATOMIC);
  2093. if (!rs)
  2094. return NULL;
  2095. rs->state = CCPResetIdle;
  2096. rs->is = is;
  2097. rs->id = id;
  2098. init_timer(&rs->timer);
  2099. rs->timer.data = (unsigned long)rs;
  2100. rs->timer.function = isdn_ppp_ccp_timer_callback;
  2101. is->reset->rs[id] = rs;
  2102. }
  2103. return rs;
  2104. }
  2105. /* A decompressor wants a reset with a set of parameters - do what is
  2106. necessary to fulfill it */
  2107. static void isdn_ppp_ccp_reset_trans(struct ippp_struct *is,
  2108. struct isdn_ppp_resetparams *rp)
  2109. {
  2110. struct ippp_ccp_reset_state *rs;
  2111. if (rp->valid) {
  2112. /* The decompressor defines parameters by itself */
  2113. if (rp->rsend) {
  2114. /* And he wants us to send a request */
  2115. if (!(rp->idval)) {
  2116. printk(KERN_ERR "ippp_ccp: decompressor must"
  2117. " specify reset id\n");
  2118. return;
  2119. }
  2120. if (is->reset->rs[rp->id]) {
  2121. /* There is already a transaction in existence
  2122. for this id. May be still waiting for a
  2123. Ack or may be wrong. */
  2124. rs = is->reset->rs[rp->id];
  2125. if (rs->state == CCPResetSentReq && rs->ta) {
  2126. printk(KERN_DEBUG "ippp_ccp: reset"
  2127. " trans still in progress"
  2128. " for id %d\n", rp->id);
  2129. } else {
  2130. printk(KERN_WARNING "ippp_ccp: reset"
  2131. " trans in wrong state %d for"
  2132. " id %d\n", rs->state, rp->id);
  2133. }
  2134. } else {
  2135. /* Ok, this is a new transaction */
  2136. printk(KERN_DEBUG "ippp_ccp: new trans for id"
  2137. " %d to be started\n", rp->id);
  2138. rs = isdn_ppp_ccp_reset_alloc_state(is, rp->id);
  2139. if (!rs) {
  2140. printk(KERN_ERR "ippp_ccp: out of mem"
  2141. " allocing ccp trans\n");
  2142. return;
  2143. }
  2144. rs->state = CCPResetSentReq;
  2145. rs->expra = rp->expra;
  2146. if (rp->dtval) {
  2147. rs->dlen = rp->dlen;
  2148. memcpy(rs->data, rp->data, rp->dlen);
  2149. }
  2150. /* HACK TODO - add link comp here */
  2151. isdn_ppp_ccp_xmit_reset(is, PPP_CCP,
  2152. CCP_RESETREQ, rs->id,
  2153. rs->data, rs->dlen);
  2154. /* Start the timer */
  2155. rs->timer.expires = jiffies + 5 * HZ;
  2156. add_timer(&rs->timer);
  2157. rs->ta = 1;
  2158. }
  2159. } else {
  2160. printk(KERN_DEBUG "ippp_ccp: no reset sent\n");
  2161. }
  2162. } else {
  2163. /* The reset params are invalid. The decompressor does not
  2164. care about them, so we just send the minimal requests
  2165. and increase ids only when an Ack is received for a
  2166. given id */
  2167. if (is->reset->rs[is->reset->lastid]) {
  2168. /* There is already a transaction in existence
  2169. for this id. May be still waiting for a
  2170. Ack or may be wrong. */
  2171. rs = is->reset->rs[is->reset->lastid];
  2172. if (rs->state == CCPResetSentReq && rs->ta) {
  2173. printk(KERN_DEBUG "ippp_ccp: reset"
  2174. " trans still in progress"
  2175. " for id %d\n", rp->id);
  2176. } else {
  2177. printk(KERN_WARNING "ippp_ccp: reset"
  2178. " trans in wrong state %d for"
  2179. " id %d\n", rs->state, rp->id);
  2180. }
  2181. } else {
  2182. printk(KERN_DEBUG "ippp_ccp: new trans for id"
  2183. " %d to be started\n", is->reset->lastid);
  2184. rs = isdn_ppp_ccp_reset_alloc_state(is,
  2185. is->reset->lastid);
  2186. if (!rs) {
  2187. printk(KERN_ERR "ippp_ccp: out of mem"
  2188. " allocing ccp trans\n");
  2189. return;
  2190. }
  2191. rs->state = CCPResetSentReq;
  2192. /* We always expect an Ack if the decompressor doesn't
  2193. know better */
  2194. rs->expra = 1;
  2195. rs->dlen = 0;
  2196. /* HACK TODO - add link comp here */
  2197. isdn_ppp_ccp_xmit_reset(is, PPP_CCP, CCP_RESETREQ,
  2198. rs->id, NULL, 0);
  2199. /* Start the timer */
  2200. rs->timer.expires = jiffies + 5 * HZ;
  2201. add_timer(&rs->timer);
  2202. rs->ta = 1;
  2203. }
  2204. }
  2205. }
  2206. /* An Ack was received for this id. This means we stop the timer and clean
  2207. up the state prior to calling the decompressors reset routine. */
  2208. static void isdn_ppp_ccp_reset_ack_rcvd(struct ippp_struct *is,
  2209. unsigned char id)
  2210. {
  2211. struct ippp_ccp_reset_state *rs = is->reset->rs[id];
  2212. if (rs) {
  2213. if (rs->ta && rs->state == CCPResetSentReq) {
  2214. /* Great, we are correct */
  2215. if (!rs->expra)
  2216. printk(KERN_DEBUG "ippp_ccp: ResetAck received"
  2217. " for id %d but not expected\n", id);
  2218. } else {
  2219. printk(KERN_INFO "ippp_ccp: ResetAck received out of"
  2220. "sync for id %d\n", id);
  2221. }
  2222. if (rs->ta) {
  2223. rs->ta = 0;
  2224. del_timer(&rs->timer);
  2225. }
  2226. isdn_ppp_ccp_reset_free_state(is, id);
  2227. } else {
  2228. printk(KERN_INFO "ippp_ccp: ResetAck received for unknown id"
  2229. " %d\n", id);
  2230. }
  2231. /* Make sure the simple reset stuff uses a new id next time */
  2232. is->reset->lastid++;
  2233. }
  2234. /*
  2235. * decompress packet
  2236. *
  2237. * if master = 0, we're trying to uncompress an per-link compressed packet,
  2238. * as opposed to an compressed reconstructed-from-MPPP packet.
  2239. * proto is updated to protocol field of uncompressed packet.
  2240. *
  2241. * retval: decompressed packet,
  2242. * same packet if uncompressed,
  2243. * NULL if decompression error
  2244. */
  2245. static struct sk_buff *isdn_ppp_decompress(struct sk_buff *skb, struct ippp_struct *is, struct ippp_struct *master,
  2246. int *proto)
  2247. {
  2248. void *stat = NULL;
  2249. struct isdn_ppp_compressor *ipc = NULL;
  2250. struct sk_buff *skb_out;
  2251. int len;
  2252. struct ippp_struct *ri;
  2253. struct isdn_ppp_resetparams rsparm;
  2254. unsigned char rsdata[IPPP_RESET_MAXDATABYTES];
  2255. if (!master) {
  2256. // per-link decompression
  2257. stat = is->link_decomp_stat;
  2258. ipc = is->link_decompressor;
  2259. ri = is;
  2260. } else {
  2261. stat = master->decomp_stat;
  2262. ipc = master->decompressor;
  2263. ri = master;
  2264. }
  2265. if (!ipc) {
  2266. // no decompressor -> we can't decompress.
  2267. printk(KERN_DEBUG "ippp: no decompressor defined!\n");
  2268. return skb;
  2269. }
  2270. BUG_ON(!stat); // if we have a compressor, stat has been set as well
  2271. if ((master && *proto == PPP_COMP) || (!master && *proto == PPP_COMPFRAG)) {
  2272. // compressed packets are compressed by their protocol type
  2273. // Set up reset params for the decompressor
  2274. memset(&rsparm, 0, sizeof(rsparm));
  2275. rsparm.data = rsdata;
  2276. rsparm.maxdlen = IPPP_RESET_MAXDATABYTES;
  2277. skb_out = dev_alloc_skb(is->mru + PPP_HDRLEN);
  2278. if (!skb_out) {
  2279. kfree_skb(skb);
  2280. printk(KERN_ERR "ippp: decomp memory allocation failure\n");
  2281. return NULL;
  2282. }
  2283. len = ipc->decompress(stat, skb, skb_out, &rsparm);
  2284. kfree_skb(skb);
  2285. if (len <= 0) {
  2286. switch (len) {
  2287. case DECOMP_ERROR:
  2288. printk(KERN_INFO "ippp: decomp wants reset %s params\n",
  2289. rsparm.valid ? "with" : "without");
  2290. isdn_ppp_ccp_reset_trans(ri, &rsparm);
  2291. break;
  2292. case DECOMP_FATALERROR:
  2293. ri->pppcfg |= SC_DC_FERROR;
  2294. /* Kick ipppd to recognize the error */
  2295. isdn_ppp_ccp_kickup(ri);
  2296. break;
  2297. }
  2298. kfree_skb(skb_out);
  2299. return NULL;
  2300. }
  2301. *proto = isdn_ppp_strip_proto(skb_out);
  2302. if (*proto < 0) {
  2303. kfree_skb(skb_out);
  2304. return NULL;
  2305. }
  2306. return skb_out;
  2307. } else {
  2308. // uncompressed packets are fed through the decompressor to
  2309. // update the decompressor state
  2310. ipc->incomp(stat, skb, *proto);
  2311. return skb;
  2312. }
  2313. }
  2314. /*
  2315. * compress a frame
  2316. * type=0: normal/bundle compression
  2317. * =1: link compression
  2318. * returns original skb if we haven't compressed the frame
  2319. * and a new skb pointer if we've done it
  2320. */
  2321. static struct sk_buff *isdn_ppp_compress(struct sk_buff *skb_in, int *proto,
  2322. struct ippp_struct *is, struct ippp_struct *master, int type)
  2323. {
  2324. int ret;
  2325. int new_proto;
  2326. struct isdn_ppp_compressor *compressor;
  2327. void *stat;
  2328. struct sk_buff *skb_out;
  2329. /* we do not compress control protocols */
  2330. if (*proto < 0 || *proto > 0x3fff) {
  2331. return skb_in;
  2332. }
  2333. if (type) { /* type=1 => Link compression */
  2334. return skb_in;
  2335. }
  2336. else {
  2337. if (!master) {
  2338. compressor = is->compressor;
  2339. stat = is->comp_stat;
  2340. }
  2341. else {
  2342. compressor = master->compressor;
  2343. stat = master->comp_stat;
  2344. }
  2345. new_proto = PPP_COMP;
  2346. }
  2347. if (!compressor) {
  2348. printk(KERN_ERR "isdn_ppp: No compressor set!\n");
  2349. return skb_in;
  2350. }
  2351. if (!stat) {
  2352. printk(KERN_ERR "isdn_ppp: Compressor not initialized?\n");
  2353. return skb_in;
  2354. }
  2355. /* Allow for at least 150 % expansion (for now) */
  2356. skb_out = alloc_skb(skb_in->len + skb_in->len / 2 + 32 +
  2357. skb_headroom(skb_in), GFP_ATOMIC);
  2358. if (!skb_out)
  2359. return skb_in;
  2360. skb_reserve(skb_out, skb_headroom(skb_in));
  2361. ret = (compressor->compress)(stat, skb_in, skb_out, *proto);
  2362. if (!ret) {
  2363. dev_kfree_skb(skb_out);
  2364. return skb_in;
  2365. }
  2366. dev_kfree_skb(skb_in);
  2367. *proto = new_proto;
  2368. return skb_out;
  2369. }
  2370. /*
  2371. * we received a CCP frame ..
  2372. * not a clean solution, but we MUST handle a few cases in the kernel
  2373. */
  2374. static void isdn_ppp_receive_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
  2375. struct sk_buff *skb, int proto)
  2376. {
  2377. struct ippp_struct *is;
  2378. struct ippp_struct *mis;
  2379. int len;
  2380. struct isdn_ppp_resetparams rsparm;
  2381. unsigned char rsdata[IPPP_RESET_MAXDATABYTES];
  2382. printk(KERN_DEBUG "Received CCP frame from peer slot(%d)\n",
  2383. lp->ppp_slot);
  2384. if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
  2385. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  2386. __func__, lp->ppp_slot);
  2387. return;
  2388. }
  2389. is = ippp_table[lp->ppp_slot];
  2390. isdn_ppp_frame_log("ccp-rcv", skb->data, skb->len, 32, is->unit, lp->ppp_slot);
  2391. if (lp->master) {
  2392. int slot = ISDN_MASTER_PRIV(lp)->ppp_slot;
  2393. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  2394. printk(KERN_ERR "%s: slot(%d) out of range\n",
  2395. __func__, slot);
  2396. return;
  2397. }
  2398. mis = ippp_table[slot];
  2399. } else
  2400. mis = is;
  2401. switch (skb->data[0]) {
  2402. case CCP_CONFREQ:
  2403. if (is->debug & 0x10)
  2404. printk(KERN_DEBUG "Disable compression here!\n");
  2405. if (proto == PPP_CCP)
  2406. mis->compflags &= ~SC_COMP_ON;
  2407. else
  2408. is->compflags &= ~SC_LINK_COMP_ON;
  2409. break;
  2410. case CCP_TERMREQ:
  2411. case CCP_TERMACK:
  2412. if (is->debug & 0x10)
  2413. printk(KERN_DEBUG "Disable (de)compression here!\n");
  2414. if (proto == PPP_CCP)
  2415. mis->compflags &= ~(SC_DECOMP_ON | SC_COMP_ON);
  2416. else
  2417. is->compflags &= ~(SC_LINK_DECOMP_ON | SC_LINK_COMP_ON);
  2418. break;
  2419. case CCP_CONFACK:
  2420. /* if we RECEIVE an ackowledge we enable the decompressor */
  2421. if (is->debug & 0x10)
  2422. printk(KERN_DEBUG "Enable decompression here!\n");
  2423. if (proto == PPP_CCP) {
  2424. if (!mis->decompressor)
  2425. break;
  2426. mis->compflags |= SC_DECOMP_ON;
  2427. } else {
  2428. if (!is->decompressor)
  2429. break;
  2430. is->compflags |= SC_LINK_DECOMP_ON;
  2431. }
  2432. break;
  2433. case CCP_RESETACK:
  2434. printk(KERN_DEBUG "Received ResetAck from peer\n");
  2435. len = (skb->data[2] << 8) | skb->data[3];
  2436. len -= 4;
  2437. if (proto == PPP_CCP) {
  2438. /* If a reset Ack was outstanding for this id, then
  2439. clean up the state engine */
  2440. isdn_ppp_ccp_reset_ack_rcvd(mis, skb->data[1]);
  2441. if (mis->decompressor && mis->decomp_stat)
  2442. mis->decompressor->
  2443. reset(mis->decomp_stat,
  2444. skb->data[0],
  2445. skb->data[1],
  2446. len ? &skb->data[4] : NULL,
  2447. len, NULL);
  2448. /* TODO: This is not easy to decide here */
  2449. mis->compflags &= ~SC_DECOMP_DISCARD;
  2450. }
  2451. else {
  2452. isdn_ppp_ccp_reset_ack_rcvd(is, skb->data[1]);
  2453. if (is->link_decompressor && is->link_decomp_stat)
  2454. is->link_decompressor->
  2455. reset(is->link_decomp_stat,
  2456. skb->data[0],
  2457. skb->data[1],
  2458. len ? &skb->data[4] : NULL,
  2459. len, NULL);
  2460. /* TODO: neither here */
  2461. is->compflags &= ~SC_LINK_DECOMP_DISCARD;
  2462. }
  2463. break;
  2464. case CCP_RESETREQ:
  2465. printk(KERN_DEBUG "Received ResetReq from peer\n");
  2466. /* Receiving a ResetReq means we must reset our compressor */
  2467. /* Set up reset params for the reset entry */
  2468. memset(&rsparm, 0, sizeof(rsparm));
  2469. rsparm.data = rsdata;
  2470. rsparm.maxdlen = IPPP_RESET_MAXDATABYTES;
  2471. /* Isolate data length */
  2472. len = (skb->data[2] << 8) | skb->data[3];
  2473. len -= 4;
  2474. if (proto == PPP_CCP) {
  2475. if (mis->compressor && mis->comp_stat)
  2476. mis->compressor->
  2477. reset(mis->comp_stat,
  2478. skb->data[0],
  2479. skb->data[1],
  2480. len ? &skb->data[4] : NULL,
  2481. len, &rsparm);
  2482. }
  2483. else {
  2484. if (is->link_compressor && is->link_comp_stat)
  2485. is->link_compressor->
  2486. reset(is->link_comp_stat,
  2487. skb->data[0],
  2488. skb->data[1],
  2489. len ? &skb->data[4] : NULL,
  2490. len, &rsparm);
  2491. }
  2492. /* Ack the Req as specified by rsparm */
  2493. if (rsparm.valid) {
  2494. /* Compressor reset handler decided how to answer */
  2495. if (rsparm.rsend) {
  2496. /* We should send a Frame */
  2497. isdn_ppp_ccp_xmit_reset(is, proto, CCP_RESETACK,
  2498. rsparm.idval ? rsparm.id
  2499. : skb->data[1],
  2500. rsparm.dtval ?
  2501. rsparm.data : NULL,
  2502. rsparm.dtval ?
  2503. rsparm.dlen : 0);
  2504. } else {
  2505. printk(KERN_DEBUG "ResetAck suppressed\n");
  2506. }
  2507. } else {
  2508. /* We answer with a straight reflected Ack */
  2509. isdn_ppp_ccp_xmit_reset(is, proto, CCP_RESETACK,
  2510. skb->data[1],
  2511. len ? &skb->data[4] : NULL,
  2512. len);
  2513. }
  2514. break;
  2515. }
  2516. }
  2517. /*
  2518. * Daemon sends a CCP frame ...
  2519. */
  2520. /* TODO: Clean this up with new Reset semantics */
  2521. /* I believe the CCP handling as-is is done wrong. Compressed frames
  2522. * should only be sent/received after CCP reaches UP state, which means
  2523. * both sides have sent CONF_ACK. Currently, we handle both directions
  2524. * independently, which means we may accept compressed frames too early
  2525. * (supposedly not a problem), but may also mean we send compressed frames
  2526. * too early, which may turn out to be a problem.
  2527. * This part of state machine should actually be handled by (i)pppd, but
  2528. * that's too big of a change now. --kai
  2529. */
  2530. /* Actually, we might turn this into an advantage: deal with the RFC in
  2531. * the old tradition of beeing generous on what we accept, but beeing
  2532. * strict on what we send. Thus we should just
  2533. * - accept compressed frames as soon as decompression is negotiated
  2534. * - send compressed frames only when decomp *and* comp are negotiated
  2535. * - drop rx compressed frames if we cannot decomp (instead of pushing them
  2536. * up to ipppd)
  2537. * and I tried to modify this file according to that. --abp
  2538. */
  2539. static void isdn_ppp_send_ccp(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *skb)
  2540. {
  2541. struct ippp_struct *mis, *is;
  2542. int proto, slot = lp->ppp_slot;
  2543. unsigned char *data;
  2544. if (!skb || skb->len < 3)
  2545. return;
  2546. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  2547. printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
  2548. __func__, slot);
  2549. return;
  2550. }
  2551. is = ippp_table[slot];
  2552. /* Daemon may send with or without address and control field comp */
  2553. data = skb->data;
  2554. if (!(is->pppcfg & SC_COMP_AC) && data[0] == 0xff && data[1] == 0x03) {
  2555. data += 2;
  2556. if (skb->len < 5)
  2557. return;
  2558. }
  2559. proto = ((int)data[0]<<8) + data[1];
  2560. if (proto != PPP_CCP && proto != PPP_CCPFRAG)
  2561. return;
  2562. printk(KERN_DEBUG "Received CCP frame from daemon:\n");
  2563. isdn_ppp_frame_log("ccp-xmit", skb->data, skb->len, 32, is->unit, lp->ppp_slot);
  2564. if (lp->master) {
  2565. slot = ISDN_MASTER_PRIV(lp)->ppp_slot;
  2566. if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
  2567. printk(KERN_ERR "%s: slot(%d) out of range\n",
  2568. __func__, slot);
  2569. return;
  2570. }
  2571. mis = ippp_table[slot];
  2572. } else
  2573. mis = is;
  2574. if (mis != is)
  2575. printk(KERN_DEBUG "isdn_ppp: Ouch! Master CCP sends on slave slot!\n");
  2576. switch (data[2]) {
  2577. case CCP_CONFREQ:
  2578. if (is->debug & 0x10)
  2579. printk(KERN_DEBUG "Disable decompression here!\n");
  2580. if (proto == PPP_CCP)
  2581. is->compflags &= ~SC_DECOMP_ON;
  2582. else
  2583. is->compflags &= ~SC_LINK_DECOMP_ON;
  2584. break;
  2585. case CCP_TERMREQ:
  2586. case CCP_TERMACK:
  2587. if (is->debug & 0x10)
  2588. printk(KERN_DEBUG "Disable (de)compression here!\n");
  2589. if (proto == PPP_CCP)
  2590. is->compflags &= ~(SC_DECOMP_ON | SC_COMP_ON);
  2591. else
  2592. is->compflags &= ~(SC_LINK_DECOMP_ON | SC_LINK_COMP_ON);
  2593. break;
  2594. case CCP_CONFACK:
  2595. /* if we SEND an ackowledge we can/must enable the compressor */
  2596. if (is->debug & 0x10)
  2597. printk(KERN_DEBUG "Enable compression here!\n");
  2598. if (proto == PPP_CCP) {
  2599. if (!is->compressor)
  2600. break;
  2601. is->compflags |= SC_COMP_ON;
  2602. } else {
  2603. if (!is->compressor)
  2604. break;
  2605. is->compflags |= SC_LINK_COMP_ON;
  2606. }
  2607. break;
  2608. case CCP_RESETACK:
  2609. /* If we send a ACK we should reset our compressor */
  2610. if (is->debug & 0x10)
  2611. printk(KERN_DEBUG "Reset decompression state here!\n");
  2612. printk(KERN_DEBUG "ResetAck from daemon passed by\n");
  2613. if (proto == PPP_CCP) {
  2614. /* link to master? */
  2615. if (is->compressor && is->comp_stat)
  2616. is->compressor->reset(is->comp_stat, 0, 0,
  2617. NULL, 0, NULL);
  2618. is->compflags &= ~SC_COMP_DISCARD;
  2619. }
  2620. else {
  2621. if (is->link_compressor && is->link_comp_stat)
  2622. is->link_compressor->reset(is->link_comp_stat,
  2623. 0, 0, NULL, 0, NULL);
  2624. is->compflags &= ~SC_LINK_COMP_DISCARD;
  2625. }
  2626. break;
  2627. case CCP_RESETREQ:
  2628. /* Just let it pass by */
  2629. printk(KERN_DEBUG "ResetReq from daemon passed by\n");
  2630. break;
  2631. }
  2632. }
  2633. int isdn_ppp_register_compressor(struct isdn_ppp_compressor *ipc)
  2634. {
  2635. ipc->next = ipc_head;
  2636. ipc->prev = NULL;
  2637. if (ipc_head) {
  2638. ipc_head->prev = ipc;
  2639. }
  2640. ipc_head = ipc;
  2641. return 0;
  2642. }
  2643. int isdn_ppp_unregister_compressor(struct isdn_ppp_compressor *ipc)
  2644. {
  2645. if (ipc->prev)
  2646. ipc->prev->next = ipc->next;
  2647. else
  2648. ipc_head = ipc->next;
  2649. if (ipc->next)
  2650. ipc->next->prev = ipc->prev;
  2651. ipc->prev = ipc->next = NULL;
  2652. return 0;
  2653. }
  2654. static int isdn_ppp_set_compressor(struct ippp_struct *is, struct isdn_ppp_comp_data *data)
  2655. {
  2656. struct isdn_ppp_compressor *ipc = ipc_head;
  2657. int ret;
  2658. void *stat;
  2659. int num = data->num;
  2660. if (is->debug & 0x10)
  2661. printk(KERN_DEBUG "[%d] Set %s type %d\n", is->unit,
  2662. (data->flags & IPPP_COMP_FLAG_XMIT) ? "compressor" : "decompressor", num);
  2663. /* If is has no valid reset state vector, we cannot allocate a
  2664. decompressor. The decompressor would cause reset transactions
  2665. sooner or later, and they need that vector. */
  2666. if (!(data->flags & IPPP_COMP_FLAG_XMIT) && !is->reset) {
  2667. printk(KERN_ERR "ippp_ccp: no reset data structure - can't"
  2668. " allow decompression.\n");
  2669. return -ENOMEM;
  2670. }
  2671. while (ipc) {
  2672. if (ipc->num == num) {
  2673. stat = ipc->alloc(data);
  2674. if (stat) {
  2675. ret = ipc->init(stat, data, is->unit, 0);
  2676. if (!ret) {
  2677. printk(KERN_ERR "Can't init (de)compression!\n");
  2678. ipc->free(stat);
  2679. stat = NULL;
  2680. break;
  2681. }
  2682. }
  2683. else {
  2684. printk(KERN_ERR "Can't alloc (de)compression!\n");
  2685. break;
  2686. }
  2687. if (data->flags & IPPP_COMP_FLAG_XMIT) {
  2688. if (data->flags & IPPP_COMP_FLAG_LINK) {
  2689. if (is->link_comp_stat)
  2690. is->link_compressor->free(is->link_comp_stat);
  2691. is->link_comp_stat = stat;
  2692. is->link_compressor = ipc;
  2693. }
  2694. else {
  2695. if (is->comp_stat)
  2696. is->compressor->free(is->comp_stat);
  2697. is->comp_stat = stat;
  2698. is->compressor = ipc;
  2699. }
  2700. }
  2701. else {
  2702. if (data->flags & IPPP_COMP_FLAG_LINK) {
  2703. if (is->link_decomp_stat)
  2704. is->link_decompressor->free(is->link_decomp_stat);
  2705. is->link_decomp_stat = stat;
  2706. is->link_decompressor = ipc;
  2707. }
  2708. else {
  2709. if (is->decomp_stat)
  2710. is->decompressor->free(is->decomp_stat);
  2711. is->decomp_stat = stat;
  2712. is->decompressor = ipc;
  2713. }
  2714. }
  2715. return 0;
  2716. }
  2717. ipc = ipc->next;
  2718. }
  2719. return -EINVAL;
  2720. }