Session group update rate calculation
[l2tpns.git] / radius.c
1 // L2TPNS Radius Stuff
2
3 #include <time.h>
4 #include <stdio.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <malloc.h>
8 #include <string.h>
9 #include <fcntl.h>
10 #include <arpa/inet.h>
11 #include <ctype.h>
12 #include <netinet/in.h>
13 #include <errno.h>
14 #include <linux/rtnetlink.h>
15
16 #include "md5.h"
17 #include "constants.h"
18 #include "l2tpns.h"
19 #include "plugin.h"
20 #include "util.h"
21 #include "cluster.h"
22
23 #ifdef LAC
24 #include "l2tplac.h"
25 #endif
26 #include "pppoe.h"
27
28 extern radiust *radius;
29 extern sessiont *session;
30 extern tunnelt *tunnel;
31 extern configt *config;
32 extern int *radfds;
33 extern ip_filtert *ip_filters;
34
35 static const hasht zero;
36
37 static void calc_auth(const void *buf, size_t len, const uint8_t *in, uint8_t *out)
38 {
39 MD5_CTX ctx;
40
41 MD5_Init(&ctx);
42 MD5_Update(&ctx, (void *)buf, 4); // code, id, length
43 MD5_Update(&ctx, (void *)in, 16); // auth
44 MD5_Update(&ctx, (void *)(buf + 20), len - 20);
45 MD5_Update(&ctx, config->radiussecret, strlen(config->radiussecret));
46 MD5_Final(out, &ctx);
47 }
48
49 // Set up socket for radius requests
50 void initrad(void)
51 {
52 int i;
53 uint16_t port = 0;
54 uint16_t min = config->radius_bind_min;
55 uint16_t max = config->radius_bind_max;
56 int inc = 1;
57 struct sockaddr_in addr;
58
59 if (min)
60 {
61 port = min;
62 if (!max)
63 max = ~0 - 1;
64 }
65 else if (max) /* no minimum specified, bind from max down */
66 {
67 port = max;
68 min = 1;
69 inc = -1;
70 }
71
72 LOG(3, 0, 0, "Creating %d sockets for RADIUS queries\n", RADIUS_FDS);
73 radfds = calloc(sizeof(int), RADIUS_FDS);
74 for (i = 0; i < RADIUS_FDS; i++)
75 {
76 int flags;
77 radfds[i] = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
78 flags = fcntl(radfds[i], F_GETFL, 0);
79 fcntl(radfds[i], F_SETFL, flags | O_NONBLOCK);
80
81 if (port)
82 {
83 int b;
84
85 memset(&addr, 0, sizeof(addr));
86 addr.sin_family = AF_INET;
87 addr.sin_addr.s_addr = INADDR_ANY;
88
89 do {
90 addr.sin_port = htons(port);
91 if ((b = bind(radfds[i], (struct sockaddr *) &addr, sizeof(addr))) < 0)
92 {
93 if ((port += inc) < min || port > max)
94 {
95 LOG(0, 0, 0, "Can't bind RADIUS socket in range %u-%u\n", min, max);
96 exit(1);
97 }
98 }
99 } while (b < 0);
100 }
101 }
102 }
103
104 void radiusclear(uint16_t r, sessionidt s)
105 {
106 if (s) sess_local[s].radius = 0;
107 memset(&radius[r], 0, sizeof(radius[r])); // radius[r].state = RADIUSNULL;
108 }
109
110 static uint16_t get_free_radius()
111 {
112 int count;
113 static uint32_t next_radius_id = 0;
114
115 for (count = MAXRADIUS; count > 0; --count)
116 {
117 ++next_radius_id; // Find the next ID to check.
118 if (next_radius_id >= MAXRADIUS)
119 next_radius_id = 1;
120
121 if (radius[next_radius_id].state == RADIUSNULL)
122 {
123 return next_radius_id;
124 }
125 }
126
127 LOG(0, 0, 0, "Can't find a free radius session! This is very bad!\n");
128 return 0;
129 }
130
131 uint16_t radiusnew(sessionidt s)
132 {
133 uint16_t r = sess_local[s].radius;
134
135 /* re-use */
136 if (r)
137 {
138 LOG(3, s, session[s].tunnel, "Re-used radius %d\n", r);
139 return r;
140 }
141
142 if (!(r = get_free_radius()))
143 {
144 LOG(1, s, session[s].tunnel, "No free RADIUS sessions\n");
145 STAT(radius_overflow);
146 return 0;
147 };
148
149 memset(&radius[r], 0, sizeof(radius[r]));
150 sess_local[s].radius = r;
151 radius[r].session = s;
152 radius[r].state = RADIUSWAIT;
153 radius[r].retry = TIME + 1200; // Wait at least 120 seconds to re-claim this.
154
155 random_data(radius[r].auth, sizeof(radius[r].auth));
156
157 LOG(3, s, session[s].tunnel, "Allocated radius %d\n", r);
158 return r;
159 }
160
161 // Send a RADIUS request
162 void radiussend(uint16_t r, uint8_t state)
163 {
164 struct sockaddr_in addr;
165 uint8_t b[4096]; // RADIUS packet
166 char pass[129];
167 int pl;
168 uint8_t *p;
169 sessionidt s;
170
171 CSTAT(radiussend);
172
173 s = radius[r].session;
174 if (!config->numradiusservers)
175 {
176 LOG(0, s, session[s].tunnel, "No RADIUS servers\n");
177 return;
178 }
179 if (!*config->radiussecret)
180 {
181 LOG(0, s, session[s].tunnel, "No RADIUS secret\n");
182 return;
183 }
184
185 if (state != RADIUSAUTH && state != RADIUSJUSTAUTH && !config->radius_accounting)
186 {
187 // Radius accounting is turned off
188 radiusclear(r, s);
189 return;
190 }
191
192 if (radius[r].state != state)
193 radius[r].try = 0;
194
195 radius[r].state = state;
196 radius[r].retry = backoff(radius[r].try++) + 20; // 3s, 4s, 6s, 10s...
197 LOG(4, s, session[s].tunnel, "Send RADIUS id %d sock %d state %s try %d\n",
198 r >> RADIUS_SHIFT, r & RADIUS_MASK,
199 radius_state(radius[r].state), radius[r].try);
200
201 if (radius[r].try > config->numradiusservers * 2)
202 {
203 if (s)
204 {
205 if (state == RADIUSAUTH || state == RADIUSJUSTAUTH)
206 sessionshutdown(s, "RADIUS timeout.", CDN_ADMIN_DISC, TERM_REAUTHENTICATION_FAILURE);
207 else
208 {
209 LOG(1, s, session[s].tunnel, "RADIUS timeout, but in state %s so don't timeout session\n",
210 radius_state(state));
211 radiusclear(r, s);
212 }
213 STAT(radius_timeout);
214 }
215 else
216 {
217 STAT(radius_retries);
218 radius[r].state = RADIUSWAIT;
219 radius[r].retry = 100;
220 }
221 return;
222 }
223 // contruct RADIUS access request
224 switch (state)
225 {
226 case RADIUSAUTH:
227 case RADIUSJUSTAUTH:
228 b[0] = AccessRequest; // access request
229 break;
230 case RADIUSSTART:
231 case RADIUSSTOP:
232 case RADIUSINTERIM:
233 b[0] = AccountingRequest; // accounting request
234 break;
235 default:
236 LOG(0, 0, 0, "Unknown radius state %d\n", state);
237 }
238 b[1] = r >> RADIUS_SHIFT; // identifier
239 memcpy(b + 4, radius[r].auth, 16);
240
241 p = b + 20;
242 if (s)
243 {
244 *p = 1; // user name
245 p[1] = strlen(session[s].user) + 2;
246 strcpy((char *) p + 2, session[s].user);
247 p += p[1];
248 }
249 if (state == RADIUSAUTH || state == RADIUSJUSTAUTH)
250 {
251 if (radius[r].chap)
252 {
253 *p = 3; // CHAP password
254 p[1] = 19; // length
255 p[2] = radius[r].id; // ID
256 memcpy(p + 3, radius[r].pass, 16); // response from CHAP request
257 p += p[1];
258 *p = 60; // CHAP Challenge
259 p[1] = 18; // length
260 memcpy(p + 2, radius[r].auth, 16);
261 p += p[1];
262 }
263 else
264 {
265 strcpy(pass, radius[r].pass);
266 pl = strlen(pass);
267 while (pl & 15)
268 pass[pl++] = 0; // pad
269 if (pl)
270 { // encrypt
271 hasht hash;
272 int p = 0;
273 while (p < pl)
274 {
275 MD5_CTX ctx;
276 MD5_Init(&ctx);
277 MD5_Update(&ctx, config->radiussecret, strlen(config->radiussecret));
278 if (p)
279 MD5_Update(&ctx, pass + p - 16, 16);
280 else
281 MD5_Update(&ctx, radius[r].auth, 16);
282 MD5_Final(hash, &ctx);
283 do
284 {
285 pass[p] ^= hash[p & 15];
286 p++;
287 }
288 while (p & 15);
289 }
290 }
291 *p = 2; // password
292 p[1] = pl + 2;
293 if (pl)
294 memcpy(p + 2, pass, pl);
295 p += p[1];
296 }
297 }
298 else // accounting
299 {
300 *p = 40; // accounting type
301 p[1] = 6;
302 *(uint32_t *) (p + 2) = htonl(state - RADIUSSTART + 1); // start=1, stop=2, interim=3
303 p += p[1];
304 if (s)
305 {
306 *p = 44; // session ID
307 p[1] = 18;
308 sprintf((char *) p + 2, "%08X%08X", session[s].unique_id, session[s].opened);
309 p += p[1];
310 if (state == RADIUSSTART)
311 { // start
312 *p = 41; // delay
313 p[1] = 6;
314 *(uint32_t *) (p + 2) = htonl(time(NULL) - session[s].opened);
315 p += p[1];
316 sess_local[s].last_interim = time_now; // Setup "first" Interim
317 }
318 else
319 { // stop, interim
320 *p = 42; // input octets
321 p[1] = 6;
322 *(uint32_t *) (p + 2) = htonl(session[s].cin);
323 p += p[1];
324
325 *p = 43; // output octets
326 p[1] = 6;
327 *(uint32_t *) (p + 2) = htonl(session[s].cout);
328 p += p[1];
329
330 *p = 46; // session time
331 p[1] = 6;
332 *(uint32_t *) (p + 2) = htonl(time(NULL) - session[s].opened);
333 p += p[1];
334
335 *p = 47; // input packets
336 p[1] = 6;
337 *(uint32_t *) (p + 2) = htonl(session[s].pin);
338 p += p[1];
339
340 *p = 48; // output packets
341 p[1] = 6;
342 *(uint32_t *) (p + 2) = htonl(session[s].pout);
343 p += p[1];
344
345 *p = 52; // input gigawords
346 p[1] = 6;
347 *(uint32_t *) (p + 2) = htonl(session[s].cin_wrap);
348 p += p[1];
349
350 *p = 53; // output gigawords
351 p[1] = 6;
352 *(uint32_t *) (p + 2) = htonl(session[s].cout_wrap);
353 p += p[1];
354
355 if (state == RADIUSSTOP && radius[r].term_cause)
356 {
357 *p = 49; // acct-terminate-cause
358 p[1] = 6;
359 *(uint32_t *) (p + 2) = htonl(radius[r].term_cause);
360 p += p[1];
361
362 if (radius[r].term_msg)
363 {
364 *p = 26; // vendor-specific
365 *(uint32_t *) (p + 2) = htonl(9); // Cisco
366 p[6] = 1; // Cisco-AVPair
367 p[7] = 2 + sprintf((char *) p + 8, "disc-cause-ext=%s", radius[r].term_msg);
368 p[1] = p[7] + 6;
369 p += p[1];
370 }
371 }
372 }
373
374 if (session[s].classlen) {
375 *p = 25; // class
376 p[1] = session[s].classlen + 2;
377 memcpy(p + 2, session[s].class, session[s].classlen);
378 p += p[1];
379 }
380
381 {
382 struct param_radius_account acct = { &tunnel[session[s].tunnel], &session[s], &p };
383 run_plugins(PLUGIN_RADIUS_ACCOUNT, &acct);
384 }
385 }
386 }
387
388 if (s)
389 {
390 *p = 5; // NAS-Port
391 p[1] = 6;
392 *(uint32_t *) (p + 2) = htonl(s);
393 p += p[1];
394
395 *p = 6; // Service-Type
396 p[1] = 6;
397 *(uint32_t *) (p + 2) = htonl((state == RADIUSJUSTAUTH ? 8 : 2)); // Authenticate only or Framed-User respectevily
398 p += p[1];
399
400 *p = 7; // Framed-Protocol
401 p[1] = htonl((state == RADIUSJUSTAUTH ? 0 : 6));
402 *(uint32_t *) (p + 2) = htonl((state == RADIUSJUSTAUTH ? 0 : 1)); // PPP
403 p += p[1];
404
405 if (session[s].ip)
406 {
407 *p = 8; // Framed-IP-Address
408 p[1] = 6;
409 *(uint32_t *) (p + 2) = htonl(session[s].ip);
410 p += p[1];
411 }
412
413 if (session[s].route[0].ip)
414 {
415 int r;
416 for (r = 0; s && r < MAXROUTE && session[s].route[r].ip; r++)
417 {
418 *p = 22; // Framed-Route
419 p[1] = sprintf((char *) p + 2, "%s/%d %s 1",
420 fmtaddr(htonl(session[s].route[r].ip), 0),
421 session[s].route[r].prefixlen,
422 fmtaddr(htonl(session[s].ip), 1)) + 2;
423
424 p += p[1];
425 }
426 }
427
428 if (session[s].session_timeout)
429 {
430 *p = 27; // Session-Timeout
431 p[1] = 6;
432 *(uint32_t *) (p + 2) = htonl(session[s].session_timeout);
433 p += p[1];
434 }
435
436 if (session[s].idle_timeout)
437 {
438 *p = 28; // Idle-Timeout
439 p[1] = 6;
440 *(uint32_t *) (p + 2) = htonl(session[s].idle_timeout);
441 p += p[1];
442 }
443
444 if (*session[s].called)
445 {
446 *p = 30; // called
447 p[1] = strlen(session[s].called) + 2;
448 strcpy((char *) p + 2, session[s].called);
449 p += p[1];
450 }
451
452 if (*session[s].calling)
453 {
454 *p = 31; // calling
455 p[1] = strlen(session[s].calling) + 2;
456 strcpy((char *) p + 2, session[s].calling);
457 p += p[1];
458 }
459 }
460
461 // NAS-IP-Address
462 *p = 4;
463 p[1] = 6;
464 *(uint32_t *)(p + 2) = config->bind_address;
465 p += p[1];
466
467 // All AVpairs added
468 *(uint16_t *) (b + 2) = htons(p - b);
469 if (state != RADIUSAUTH && state != RADIUSJUSTAUTH)
470 {
471 // Build auth for accounting packet
472 calc_auth(b, p - b, zero, b + 4);
473 memcpy(radius[r].auth, b + 4, 16);
474 }
475 memset(&addr, 0, sizeof(addr));
476 addr.sin_family = AF_INET;
477 *(uint32_t *) & addr.sin_addr = config->radiusserver[(radius[r].try - 1) % config->numradiusservers];
478 {
479 // get radius port
480 uint16_t port = config->radiusport[(radius[r].try - 1) % config->numradiusservers];
481 // assume RADIUS accounting port is the authentication port +1
482 addr.sin_port = htons((state == RADIUSAUTH || state == RADIUSJUSTAUTH) ? port : port+1);
483 }
484
485 LOG_HEX(5, "RADIUS Send", b, (p - b));
486 sendto(radfds[r & RADIUS_MASK], b, p - b, 0, (void *) &addr, sizeof(addr));
487 }
488
489 static void handle_avpair(sessionidt s, uint8_t *avp, int len)
490 {
491 uint8_t *key = avp;
492 uint8_t *value = memchr(avp, '=', len);
493 uint8_t tmp[2048] = "";
494
495 if (value)
496 {
497 *value++ = 0;
498 len -= value - key;
499 }
500 else
501 {
502 value = tmp;
503 len = 0;
504 }
505
506 // strip quotes
507 if (len > 2 && (*value == '"' || *value == '\'') && value[len - 1] == *value)
508 {
509 value++;
510 len--;
511 value[len - 1] = 0;
512 }
513 // copy and null terminate
514 else if (len < sizeof(tmp) - 1)
515 {
516 memcpy(tmp, value, len);
517 tmp[len] = 0;
518 value = tmp;
519 }
520 else
521 return;
522
523 // Run hooks
524 {
525 struct param_radius_response p = { &tunnel[session[s].tunnel], &session[s], (char *) key, (char *) value };
526 run_plugins(PLUGIN_RADIUS_RESPONSE, &p);
527 }
528 }
529
530 // process RADIUS response
531 void processrad(uint8_t *buf, int len, char socket_index)
532 {
533 uint8_t b[MAXETHER];
534 uint16_t r;
535 sessionidt s;
536 tunnelidt t = 0;
537 hasht hash;
538 uint8_t routes = 0;
539 int r_code;
540 int r_id;
541 #ifdef LAC
542 int OpentunnelReq = 0;
543 #endif
544
545 CSTAT(processrad);
546
547 LOG_HEX(5, "RADIUS Response", buf, len);
548 if (len < 20 || len < ntohs(*(uint16_t *) (buf + 2)))
549 {
550 LOG(1, 0, 0, "Duff RADIUS response length %d\n", len);
551 return ;
552 }
553
554 r_code = buf[0]; // response type
555 r_id = buf[1]; // radius reply indentifier.
556
557 len = ntohs(*(uint16_t *) (buf + 2));
558 r = socket_index | (r_id << RADIUS_SHIFT);
559 s = radius[r].session;
560 LOG(3, s, session[s].tunnel, "Received %s, radius %d response for session %u (%s, id %d)\n",
561 radius_state(radius[r].state), r, s, radius_code(r_code), r_id);
562
563 if (!s && radius[r].state != RADIUSSTOP)
564 {
565 LOG(1, s, session[s].tunnel, " Unexpected RADIUS response\n");
566 return;
567 }
568 if (radius[r].state != RADIUSAUTH && radius[r].state != RADIUSJUSTAUTH && radius[r].state != RADIUSSTART
569 && radius[r].state != RADIUSSTOP && radius[r].state != RADIUSINTERIM)
570 {
571 LOG(1, s, session[s].tunnel, " Unexpected RADIUS response\n");
572 return;
573 }
574 t = session[s].tunnel;
575 calc_auth(buf, len, radius[r].auth, hash);
576 do {
577 if (memcmp(hash, buf + 4, 16))
578 {
579 LOG(0, s, session[s].tunnel, " Incorrect auth on RADIUS response!! (wrong secret in radius config?)\n");
580 return; // Do nothing. On timeout, it will try the next radius server.
581 }
582
583 if (((radius[r].state == RADIUSAUTH ||radius[r].state == RADIUSJUSTAUTH) && r_code != AccessAccept && r_code != AccessReject) ||
584 ((radius[r].state == RADIUSSTART || radius[r].state == RADIUSSTOP || radius[r].state == RADIUSINTERIM) && r_code != AccountingResponse))
585 {
586 LOG(1, s, session[s].tunnel, " Unexpected RADIUS response %s\n", radius_code(r_code));
587 return; // We got something we didn't expect. Let the timeouts take
588 // care off finishing the radius session if that's really correct.
589 }
590
591 if (radius[r].state == RADIUSAUTH || radius[r].state == RADIUSJUSTAUTH)
592 {
593 // run post-auth plugin
594 struct param_post_auth packet = {
595 &tunnel[t],
596 &session[s],
597 session[s].user,
598 (r_code == AccessAccept),
599 radius[r].chap ? PPPCHAP : PPPPAP
600 };
601
602 run_plugins(PLUGIN_POST_AUTH, &packet);
603 r_code = packet.auth_allowed ? AccessAccept : AccessReject;
604
605 #ifndef LAC
606 // process auth response
607 if (radius[r].chap)
608 {
609 // CHAP
610 uint8_t *p = makeppp(b, sizeof(b), 0, 0, s, t, PPPCHAP, 0, 0, 0);
611 if (!p) return; // Abort!
612
613 *p = (r_code == AccessAccept) ? 3 : 4; // ack/nak
614 p[1] = radius[r].id;
615 *(uint16_t *) (p + 2) = ntohs(4); // no message
616 tunnelsend(b, (p - b) + 4, t); // send it
617
618 LOG(3, s, session[s].tunnel, " CHAP User %s authentication %s.\n", session[s].user,
619 (r_code == AccessAccept) ? "allowed" : "denied");
620 }
621 else
622 {
623 // PAP
624 uint8_t *p = makeppp(b, sizeof(b), 0, 0, s, t, PPPPAP, 0, 0, 0);
625 if (!p) return; // Abort!
626
627 // ack/nak
628 *p = r_code;
629 p[1] = radius[r].id;
630 *(uint16_t *) (p + 2) = ntohs(5);
631 p[4] = 0; // no message
632 tunnelsend(b, (p - b) + 5, t); // send it
633
634 LOG(3, s, session[s].tunnel, " PAP User %s authentication %s.\n", session[s].user,
635 (r_code == AccessAccept) ? "allowed" : "denied");
636 }
637 #endif
638
639 if (r_code == AccessAccept)
640 {
641 // Login successful
642 // Extract IP, routes, etc
643 uint8_t *p = buf + 20;
644 uint8_t *e = buf + len;
645 #ifdef LAC
646 uint8_t tag;
647 uint8_t strtemp[256];
648 lac_reset_rad_tag_tunnel_ctxt();
649 #endif
650 for (; p + 2 <= e && p[1] && p + p[1] <= e; p += p[1])
651 {
652 if (*p == 26 && p[1] >= 7)
653 {
654 // Vendor-Specific Attribute
655 uint32_t vendor = ntohl(*(int *)(p + 2));
656 uint8_t attrib = *(p + 6);
657 int attrib_length = *(p + 7) - 2;
658
659 LOG(4, s, session[s].tunnel, " Radius reply contains Vendor-Specific. Vendor=%u Attrib=%u Length=%d\n", vendor, attrib, attrib_length);
660 if (vendor == 9 && attrib == 1) // Cisco-AVPair
661 {
662 if (attrib_length < 0) continue;
663 LOG(3, s, session[s].tunnel, " Cisco-AVPair value: %.*s\n",
664 attrib_length, p + 8);
665
666 handle_avpair(s, p + 8, attrib_length);
667 continue;
668 }
669 else if (vendor == 529 && attrib >= 135 && attrib <= 136) // Ascend
670 {
671 // handle old-format ascend DNS attributes below
672 p += 6;
673 }
674 else if (vendor == 64520) // Sames
675 {
676 //Sames vendor-specific 64520
677 uint8_t *pvs = p + 6; // pvs set to begin to attribute
678 LOG(3, s, session[s].tunnel, " Sames vendor-specific: %d, Attrib: %d, lenght: %d\n", vendor, attrib, attrib_length);
679 grp_processvendorspecific(s, pvs);
680 continue;
681 }
682 else
683 {
684 LOG(3, s, session[s].tunnel, " Unknown vendor-specific: %d, Attrib: %d\n", vendor, attrib);
685 continue;
686 }
687 }
688
689 if (*p == 8)
690 {
691 // Framed-IP-Address
692 if (p[1] < 6) continue;
693 session[s].ip = ntohl(*(uint32_t *) (p + 2));
694 session[s].ip_pool_index = -1;
695 LOG(3, s, session[s].tunnel, " Radius reply contains IP address %s\n",
696 fmtaddr(htonl(session[s].ip), 0));
697
698 if (session[s].ip == 0xFFFFFFFE)
699 session[s].ip = 0; // assign from pool
700 }
701 else if (*p == 135)
702 {
703 // DNS address
704 if (p[1] < 6) continue;
705 session[s].dns1 = ntohl(*(uint32_t *) (p + 2));
706 LOG(3, s, session[s].tunnel, " Radius reply contains primary DNS address %s\n",
707 fmtaddr(htonl(session[s].dns1), 0));
708 }
709 else if (*p == 136)
710 {
711 // DNS address
712 if (p[1] < 6) continue;
713 session[s].dns2 = ntohl(*(uint32_t *) (p + 2));
714 LOG(3, s, session[s].tunnel, " Radius reply contains secondary DNS address %s\n",
715 fmtaddr(htonl(session[s].dns2), 0));
716 }
717 else if (*p == 22)
718 {
719 // Framed-Route
720 in_addr_t ip = 0;
721 uint8_t u = 0;
722 uint8_t bits = 0;
723 uint8_t *n = p + 2;
724 uint8_t *e = p + p[1];
725 while (n < e && (isdigit(*n) || *n == '.'))
726 {
727 if (*n == '.')
728 {
729 ip = (ip << 8) + u;
730 u = 0;
731 }
732 else
733 u = u * 10 + *n - '0';
734 n++;
735 }
736 ip = (ip << 8) + u;
737 if (*n == '/')
738 {
739 n++;
740 while (n < e && isdigit(*n))
741 bits = bits * 10 + *n++ - '0';
742 }
743 else if ((ip >> 24) < 128)
744 bits = 8;
745 else if ((ip >> 24) < 192)
746 bits = 16;
747 else
748 bits = 24;
749
750 if (routes == MAXROUTE)
751 {
752 LOG(1, s, session[s].tunnel, " Too many routes\n");
753 }
754 else if (ip)
755 {
756 LOG(3, s, session[s].tunnel, " Radius reply contains route for %s/%d\n",
757 fmtaddr(htonl(ip), 0), bits);
758
759 session[s].route[routes].ip = ip;
760 session[s].route[routes].prefixlen = bits;
761 routes++;
762 }
763 }
764 else if (*p == 11)
765 {
766 // Filter-Id
767 char *filter = (char *) p + 2;
768 int l = p[1] - 2;
769 char *suffix;
770 int f;
771 uint8_t *fp = 0;
772
773 LOG(3, s, session[s].tunnel, " Radius reply contains Filter-Id \"%.*s\"\n", l, filter);
774 if ((suffix = memchr(filter, '.', l)))
775 {
776 int b = suffix - filter;
777 if (l - b == 3 && !memcmp("in", suffix+1, 2))
778 fp = &session[s].filter_in;
779 else if (l - b == 4 && !memcmp("out", suffix+1, 3))
780 fp = &session[s].filter_out;
781
782 l = b;
783 }
784
785 if (!fp)
786 {
787 LOG(3, s, session[s].tunnel, " Invalid filter\n");
788 continue;
789 }
790
791 if ((f = find_filter(filter, l)) < 0 || !*ip_filters[f].name)
792 {
793 LOG(3, s, session[s].tunnel, " Unknown filter\n");
794 }
795 else
796 {
797 *fp = f + 1;
798 ip_filters[f].used++;
799 }
800 }
801 else if (*p == 27)
802 {
803 // Session-Timeout
804 if (p[1] < 6) continue;
805 session[s].session_timeout = ntohl(*(uint32_t *)(p + 2));
806 LOG(3, s, session[s].tunnel, " Radius reply contains Session-Timeout = %u\n", session[s].session_timeout);
807 if(!session[s].session_timeout && config->kill_timedout_sessions)
808 sessionshutdown(s, "Session timeout is zero", CDN_ADMIN_DISC, 0);
809 }
810 else if (*p == 28)
811 {
812 // Idle-Timeout
813 if (p[1] < 6) continue;
814 session[s].idle_timeout = ntohl(*(uint32_t *)(p + 2));
815 LOG(3, s, session[s].tunnel, " Radius reply contains Idle-Timeout = %u\n", session[s].idle_timeout);
816 }
817 else if (*p == 99)
818 {
819 // Framed-IPv6-Route
820 struct in6_addr r6;
821 int prefixlen;
822 uint8_t *n = p + 2;
823 uint8_t *e = p + p[1];
824 uint8_t *m = memchr(n, '/', e - p);
825
826 *m++ = 0;
827 inet_pton(AF_INET6, (char *) n, &r6);
828
829 prefixlen = 0;
830 while (m < e && isdigit(*m)) {
831 prefixlen = prefixlen * 10 + *m++ - '0';
832 }
833
834 if (prefixlen)
835 {
836 LOG(3, s, session[s].tunnel,
837 " Radius reply contains route for %s/%d\n",
838 n, prefixlen);
839 session[s].ipv6route = r6;
840 session[s].ipv6prefixlen = prefixlen;
841 }
842 }
843 else if (*p == 25)
844 {
845 // Class
846 if (p[1] < 3) continue;
847 session[s].classlen = p[1] - 2;
848 if (session[s].classlen > MAXCLASS)
849 session[s].classlen = MAXCLASS;
850 memcpy(session[s].class, p + 2, session[s].classlen);
851 }
852 #ifdef LAC
853 else if (*p == 64)
854 {
855 // Tunnel-Type
856 if (p[1] != 6) continue;
857 tag = p[2];
858 LOG(3, s, session[s].tunnel, " Radius reply Tunnel-Type:%d %d\n",
859 tag, ntohl(*(uint32_t *)(p + 2)) & 0xFFFFFF);
860 // Fill context
861 lac_set_rad_tag_tunnel_type(tag, ntohl(*(uint32_t *)(p + 2)) & 0xFFFFFF);
862 /* Request open tunnel to remote LNS*/
863 OpentunnelReq = 1;
864 }
865 else if (*p == 65)
866 {
867 // Tunnel-Medium-Type
868 if (p[1] < 6) continue;
869 tag = p[2];
870 LOG(3, s, session[s].tunnel, " Radius reply Tunnel-Medium-Type:%d %d\n",
871 tag, ntohl(*(uint32_t *)(p + 2)) & 0xFFFFFF);
872 // Fill context
873 lac_set_rad_tag_tunnel_medium_type(tag, ntohl(*(uint32_t *)(p + 2)) & 0xFFFFFF);
874 }
875 else if (*p == 67)
876 {
877 // Tunnel-Server-Endpoint
878 if (p[1] < 3) continue;
879 tag = p[2];
880 //If the Tag field is greater than 0x1F,
881 // it SHOULD be interpreted as the first byte of the following String field.
882 memset(strtemp, 0, 256);
883 if (tag > 0x1F)
884 {
885 tag = 0;
886 memcpy(strtemp, (p + 2), p[1]-2);
887 }
888 else
889 memcpy(strtemp, (p + 3), p[1]-3);
890
891 LOG(3, s, session[s].tunnel, " Radius reply Tunnel-Server-Endpoint:%d %s\n", tag, strtemp);
892 // Fill context
893 lac_set_rad_tag_tunnel_serv_endpt(tag, (char *) strtemp);
894 }
895 else if (*p == 69)
896 {
897 // Tunnel-Password
898 size_t lentemp;
899
900 if (p[1] < 5) continue;
901 tag = p[2];
902
903 memset(strtemp, 0, 256);
904 lentemp = p[1]-3;
905 memcpy(strtemp, (p + 3), lentemp);
906 if (!rad_tunnel_pwdecode(strtemp, &lentemp, config->radiussecret, radius[r].auth))
907 {
908 LOG_HEX(3, "Error Decode Tunnel-Password, Dump Radius reponse:", p, p[1]);
909 continue;
910 }
911
912 LOG(3, s, session[s].tunnel, " Radius reply Tunnel-Password:%d %s\n", tag, strtemp);
913 if (strlen((char *) strtemp) > 63)
914 {
915 LOG(1, s, session[s].tunnel, "tunnel password is too long (>63)\n");
916 continue;
917 }
918 // Fill context
919 lac_set_rad_tag_tunnel_password(tag, (char *) strtemp);
920 }
921 else if (*p == 82)
922 {
923 // Tunnel-Assignment-Id
924 if (p[1] < 3) continue;
925 tag = p[2];
926 //If the Tag field is greater than 0x1F,
927 // it SHOULD be interpreted as the first byte of the following String field.
928 memset(strtemp, 0, 256);
929 if (tag > 0x1F)
930 {
931 tag = 0;
932 memcpy(strtemp, (p + 2), p[1]-2);
933 }
934 else
935 memcpy(strtemp, (p + 3), p[1]-3);
936
937 LOG(3, s, session[s].tunnel, " Radius reply Tunnel-Assignment-Id:%d %s\n", tag, strtemp);
938 // Fill context
939 lac_set_rad_tag_tunnel_assignment_id(tag, (char *) strtemp);
940 }
941 #endif
942 }
943 }
944 else if (r_code == AccessReject)
945 {
946 LOG(2, s, session[s].tunnel, " Authentication rejected for %s\n", session[s].user);
947 sessionkill(s, "Authentication rejected");
948 break;
949 }
950
951 #ifdef LAC
952 if ((!config->disable_lac_func) && OpentunnelReq)
953 {
954 char assignment_id[256];
955 // Save radius tag context to conf
956 lac_save_rad_tag_tunnels(s);
957
958 memset(assignment_id, 0, 256);
959 if (!lac_rad_select_assignment_id(s, assignment_id))
960 break; // Error no assignment_id
961
962 LOG(3, s, session[s].tunnel, "Select Tunnel Remote LNS for assignment_id == %s\n", assignment_id);
963
964 if (lac_rad_forwardtoremotelns(s, assignment_id, session[s].user))
965 {
966 int ro;
967 // Sanity check, no local IP to session forwarded
968 session[s].ip = 0;
969 for (ro = 0; r < MAXROUTE && session[s].route[ro].ip; r++)
970 {
971 session[s].route[ro].ip = 0;
972 }
973 break;
974 }
975 }
976
977 // process auth response
978 if (radius[r].chap)
979 {
980 // CHAP
981 uint8_t *p = makeppp(b, sizeof(b), 0, 0, s, t, PPPCHAP, 0, 0, 0);
982 if (!p) return; // Abort!
983
984 *p = (r_code == AccessAccept) ? 3 : 4; // ack/nak
985 p[1] = radius[r].id;
986 *(uint16_t *) (p + 2) = ntohs(4); // no message
987 tunnelsend(b, (p - b) + 4, t); // send it
988
989 LOG(3, s, session[s].tunnel, " CHAP User %s authentication %s.\n", session[s].user,
990 (r_code == AccessAccept) ? "allowed" : "denied");
991 }
992 else
993 {
994 // PAP
995 uint8_t *p = makeppp(b, sizeof(b), 0, 0, s, t, PPPPAP, 0, 0, 0);
996 if (!p) return; // Abort!
997
998 // ack/nak
999 *p = r_code;
1000 p[1] = radius[r].id;
1001 *(uint16_t *) (p + 2) = ntohs(5);
1002 p[4] = 0; // no message
1003 tunnelsend(b, (p - b) + 5, t); // send it
1004
1005 LOG(3, s, session[s].tunnel, " PAP User %s authentication %s.\n", session[s].user,
1006 (r_code == AccessAccept) ? "allowed" : "denied");
1007 }
1008 #endif
1009
1010 if (!session[s].dns1 && config->default_dns1)
1011 {
1012 session[s].dns1 = ntohl(config->default_dns1);
1013 LOG(3, s, t, " Sending dns1 = %s\n", fmtaddr(config->default_dns1, 0));
1014 }
1015 if (!session[s].dns2 && config->default_dns2)
1016 {
1017 session[s].dns2 = ntohl(config->default_dns2);
1018 LOG(3, s, t, " Sending dns2 = %s\n", fmtaddr(config->default_dns2, 0));
1019 }
1020
1021 // Valid Session, set it up
1022 session[s].unique_id = 0;
1023 sessionsetup(s, t);
1024 }
1025 else
1026 {
1027 // An ack for a stop or start record.
1028 LOG(3, s, t, " RADIUS accounting ack recv in state %s\n", radius_state(radius[r].state));
1029 break;
1030 }
1031 } while (0);
1032
1033 // finished with RADIUS
1034 radiusclear(r, s);
1035 }
1036
1037 // Send a retry for RADIUS/CHAP message
1038 void radiusretry(uint16_t r)
1039 {
1040 sessionidt s = radius[r].session;
1041 tunnelidt t = 0;
1042
1043 CSTAT(radiusretry);
1044
1045 if (s) t = session[s].tunnel;
1046
1047 switch (radius[r].state)
1048 {
1049 case RADIUSCHAP: // sending CHAP down PPP
1050 sendchap(s, t);
1051 break;
1052 case RADIUSAUTH: // sending auth to RADIUS server
1053 case RADIUSJUSTAUTH: // sending auth to RADIUS server
1054 case RADIUSSTART: // sending start accounting to RADIUS server
1055 case RADIUSSTOP: // sending stop accounting to RADIUS server
1056 case RADIUSINTERIM: // sending interim accounting to RADIUS server
1057 radiussend(r, radius[r].state);
1058 break;
1059 default:
1060 case RADIUSNULL: // Not in use
1061 case RADIUSWAIT: // waiting timeout before available, in case delayed reply from RADIUS server
1062 // free up RADIUS task
1063 radiusclear(r, s);
1064 LOG(3, s, session[s].tunnel, "Freeing up radius session %d\n", r);
1065 break;
1066 }
1067 }
1068
1069 extern int daefd;
1070
1071 void processdae(uint8_t *buf, int len, struct sockaddr_in *addr, int alen, struct in_addr *local)
1072 {
1073 int i, r_code, r_id, length, attribute_length;
1074 uint8_t *packet, attribute;
1075 hasht hash;
1076 char username[MAXUSER] = "";
1077 in_addr_t nas = 0;
1078 in_addr_t ip = 0;
1079 uint32_t port = 0;
1080 uint32_t error = 0;
1081 sessionidt s = 0;
1082 tunnelidt t;
1083 int fin = -1;
1084 int fout = -1;
1085 uint8_t *avpair[64];
1086 int avpair_len[sizeof(avpair)/sizeof(*avpair)];
1087 int avp = 0;
1088 int auth_only = 0;
1089 uint8_t *p;
1090
1091 LOG(3, 0, 0, "DAE request from %s\n", fmtaddr(addr->sin_addr.s_addr, 0));
1092 LOG_HEX(5, "DAE Request", buf, len);
1093
1094 if (len < 20 || len < ntohs(*(uint16_t *) (buf + 2)))
1095 {
1096 LOG(1, 0, 0, "Duff DAE request length %d\n", len);
1097 return;
1098 }
1099
1100 r_code = buf[0]; // request type
1101 r_id = buf[1]; // radius indentifier.
1102
1103 if (r_code != DisconnectRequest && r_code != CoARequest)
1104 {
1105 LOG(1, 0, 0, "Unrecognised DAE request %s\n", radius_code(r_code));
1106 return;
1107 }
1108
1109 if (!config->cluster_iam_master)
1110 {
1111 master_forward_dae_packet(buf, len, addr->sin_addr.s_addr, addr->sin_port);
1112 return;
1113 }
1114
1115 len = ntohs(*(uint16_t *) (buf + 2));
1116
1117 LOG(3, 0, 0, "Received DAE %s, id %d\n", radius_code(r_code), r_id);
1118
1119 // check authenticator
1120 calc_auth(buf, len, zero, hash);
1121 if (memcmp(hash, buf + 4, 16) != 0)
1122 {
1123 LOG(1, 0, 0, "Incorrect vector in DAE request (wrong secret in radius config?)\n");
1124 return;
1125 }
1126
1127 // unpack attributes
1128 packet = buf + 20;
1129 length = len - 20;
1130
1131 while (length > 0)
1132 {
1133 attribute = *packet++;
1134 attribute_length = *packet++;
1135 if (attribute_length < 2)
1136 break;
1137
1138 length -= attribute_length;
1139 attribute_length -= 2;
1140 switch (attribute)
1141 {
1142 case 1: /* username */
1143 len = attribute_length < MAXUSER ? attribute_length : MAXUSER - 1;
1144 memcpy(username, packet, len);
1145 username[len] = 0;
1146 LOG(4, 0, 0, " Received DAE User-Name: %s\n", username);
1147 break;
1148
1149 case 4: /* nas ip address */
1150 nas = *(uint32_t *) packet; // net order
1151 if (nas != config->bind_address)
1152 error = 403; // NAS identification mismatch
1153
1154 LOG(4, 0, 0, " Received DAE NAS-IP-Address: %s\n", fmtaddr(nas, 0));
1155 break;
1156
1157 case 5: /* nas port */
1158 port = ntohl(*(uint32_t *) packet);
1159 if (port < 1 || port > MAXSESSION)
1160 error = 404;
1161
1162 LOG(4, 0, 0, " Received DAE NAS-Port: %u\n", port);
1163 break;
1164
1165 case 6: /* service type */
1166 {
1167 uint32_t service_type = ntohl(*(uint32_t *) packet);
1168 auth_only = service_type == 8; // Authenticate only
1169
1170 LOG(4, 0, 0, " Received DAE Service-Type: %u\n", service_type);
1171 }
1172 break;
1173
1174 case 8: /* ip address */
1175 ip = *(uint32_t *) packet; // net order
1176 LOG(4, 0, 0, " Received DAE Framed-IP-Address: %s\n", fmtaddr(ip, 0));
1177 break;
1178
1179 case 11: /* filter id */
1180 LOG(4, 0, 0, " Received DAE Filter-Id: %.*s\n", attribute_length, packet);
1181 if (!(p = memchr(packet, '.', attribute_length)))
1182 {
1183 error = 404; // invalid request
1184 break;
1185 }
1186
1187 len = p - packet;
1188 i = find_filter((char *) packet, len);
1189 if (i < 0 || !*ip_filters[i].name)
1190 {
1191 error = 404;
1192 break;
1193 }
1194
1195 if (!memcmp(p, ".in", attribute_length - len))
1196 fin = i + 1;
1197 else if (!memcmp(p, ".out", attribute_length - len))
1198 fout = i + 1;
1199 else
1200 error = 404;
1201
1202 break;
1203
1204 case 26: /* vendor specific */
1205 if (attribute_length >= 6
1206 && ntohl(*(uint32_t *) packet) == 9 // Cisco
1207 && *(packet + 4) == 1 // Cisco-AVPair
1208 && *(packet + 5) >= 2) // length
1209 {
1210 int len = *(packet + 5) - 2;
1211 uint8_t *a = packet + 6;
1212
1213 LOG(4, 0, 0, " Received DAE Cisco-AVPair: %.*s\n", len, a);
1214 if (avp < sizeof(avpair)/sizeof(*avpair) - 1)
1215 {
1216 avpair[avp] = a;
1217 avpair_len[avp++] = len;
1218 }
1219 }
1220 break;
1221 }
1222
1223 packet += attribute_length;
1224 }
1225
1226 if (!error && auth_only)
1227 {
1228 if (fin != -1 || fout != -1 || avp)
1229 error = 401; // unsupported attribute
1230 else
1231 error = 405; // unsupported service
1232 }
1233
1234 if (!error && !(port || ip || *username))
1235 error = 402; // missing attribute
1236
1237 // exact match for SID if given
1238 if (!error && port)
1239 {
1240 s = port;
1241 if (!session[s].opened)
1242 error = 503; // not found
1243 }
1244
1245 if (!error && ip)
1246 {
1247 // find/check session by IP
1248 i = sessionbyip(ip);
1249 if (!i || (s && s != i)) // not found or mismatching port
1250 error = 503;
1251 else
1252 s = i;
1253 }
1254
1255 if (!error && *username)
1256 {
1257 if (s)
1258 {
1259 if (strcmp(session[s].user, username))
1260 error = 503;
1261 }
1262 else if (!(s = sessionbyuser(username)))
1263 error = 503;
1264 }
1265
1266 t = session[s].tunnel;
1267
1268 switch (r_code)
1269 {
1270 case DisconnectRequest: // Packet of Disconnect/Death
1271 if (error)
1272 {
1273 r_code = DisconnectNAK;
1274 break;
1275 }
1276
1277 LOG(3, s, t, " DAE Disconnect %d (%s)\n", s, session[s].user);
1278 r_code = DisconnectACK;
1279
1280 sessionshutdown(s, "Requested by PoD", CDN_ADMIN_DISC, TERM_ADMIN_RESET); // disconnect session
1281 break;
1282
1283 case CoARequest: // Change of Authorization
1284 if (error)
1285 {
1286 r_code = CoANAK;
1287 break;
1288 }
1289
1290 LOG(3, s, t, " DAE Change %d (%s)\n", s, session[s].user);
1291 r_code = CoAACK;
1292
1293 // reset
1294 {
1295 struct param_radius_reset p = { &tunnel[session[s].tunnel], &session[s] };
1296 run_plugins(PLUGIN_RADIUS_RESET, &p);
1297 }
1298
1299 // apply filters
1300 if (fin == -1)
1301 fin = 0;
1302 else
1303 LOG(3, s, t, " Filter in %d (%s)\n", fin, ip_filters[fin - 1].name);
1304
1305 if (fout == -1)
1306 fout = 0;
1307 else
1308 LOG(3, s, t, " Filter out %d (%s)\n", fout, ip_filters[fout - 1].name);
1309
1310 filter_session(s, fin, fout);
1311
1312 // process cisco av-pair(s)
1313 for (i = 0; i < avp; i++)
1314 {
1315 LOG(3, s, t, " Cisco-AVPair: %.*s\n", avpair_len[i], avpair[i]);
1316 handle_avpair(s, avpair[i], avpair_len[i]);
1317 }
1318
1319 cluster_send_session(s);
1320 break;
1321 }
1322
1323 // send response
1324 packet = buf;
1325 *packet++ = r_code;
1326 *packet++ = r_id;
1327 // skip len + auth
1328 packet += 2 + 16;
1329 len = packet - buf;
1330
1331 // add attributes
1332 if (error)
1333 {
1334 // add error cause
1335 *packet++ = 101;
1336 *packet++ = 6;
1337 *(uint32_t *) packet = htonl(error);
1338 len += 6;
1339 }
1340
1341 *((uint16_t *)(buf + 2)) = htons(len);
1342
1343 // make vector
1344 calc_auth(buf, len, hash, buf + 4);
1345
1346 LOG(3, 0, 0, "Sending DAE %s, id=%d\n", radius_code(r_code), r_id);
1347
1348 // send DAE response
1349 if (sendtofrom(daefd, buf, len, MSG_DONTWAIT | MSG_NOSIGNAL, (struct sockaddr *) addr, alen, local) < 0)
1350 LOG(0, 0, 0, "Error sending DAE response packet: %s\n", strerror(errno));
1351 }
1352
1353 #ifdef LAC
1354 // Decrypte the encrypted Tunnel Password.
1355 // Defined in RFC-2868.
1356 // the pl2tpsecret buffer must set to 256 characters.
1357 // return 0 on decoding error else length of decoded l2tpsecret
1358 int rad_tunnel_pwdecode(uint8_t *pl2tpsecret, size_t *pl2tpsecretlen,
1359 const char *radiussecret, const uint8_t * auth)
1360 {
1361 MD5_CTX ctx, oldctx;
1362 hasht hash;
1363 int secretlen;
1364 unsigned i, n, len, decodedlen;
1365
1366 /* 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 6 7
1367 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1368 | Salt | Salt | String ..........
1369 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
1370
1371 len = *pl2tpsecretlen;
1372
1373 if (len < 2)
1374 {
1375 LOG(1, 0, 0, "tunnel password is too short, We need at least a salt\n");
1376 return 0;
1377 }
1378
1379 if (len <= 3)
1380 {
1381 pl2tpsecret[0] = 0;
1382 *pl2tpsecretlen = 0;
1383 LOG(1, 0, 0, "tunnel passwd is empty !!!\n");
1384 return 0;
1385 }
1386
1387 len -= 2; /* discount the salt */
1388
1389 //Use the secret to setup the decryption
1390 secretlen = strlen(radiussecret);
1391
1392 MD5_Init(&ctx);
1393 MD5_Update(&ctx, (void *) radiussecret, secretlen);
1394 oldctx = ctx; /* save intermediate work */
1395
1396 // Set up the initial key:
1397 // b(1) = MD5(radiussecret + auth + salt)
1398 MD5_Update(&ctx, (void *) auth, 16);
1399 MD5_Update(&ctx, pl2tpsecret, 2);
1400
1401 decodedlen = 0;
1402 for (n = 0; n < len; n += 16)
1403 {
1404 int base = 0;
1405
1406 if (n == 0)
1407 {
1408 MD5_Final(hash, &ctx);
1409
1410 ctx = oldctx;
1411
1412 // the first octet, it's the 'data_len'
1413 // Check is correct
1414 decodedlen = pl2tpsecret[2] ^ hash[0];
1415 if (decodedlen >= len)
1416 {
1417 LOG(1, 0, 0, "tunnel password is too long !!!\n");
1418 return 0;
1419 }
1420
1421 MD5_Update(&ctx, pl2tpsecret + 2, 16);
1422 base = 1;
1423 } else
1424 {
1425 MD5_Final(hash, &ctx);
1426
1427 ctx = oldctx;
1428 MD5_Update(&ctx, pl2tpsecret + n + 2, 16);
1429 }
1430
1431 for (i = base; i < 16; i++)
1432 {
1433 pl2tpsecret[n + i - 1] = pl2tpsecret[n + i + 2] ^ hash[i];
1434 }
1435 }
1436
1437 if (decodedlen > 239) decodedlen = 239;
1438
1439 *pl2tpsecretlen = decodedlen;
1440 pl2tpsecret[decodedlen] = 0;
1441
1442 return decodedlen;
1443 };
1444 #endif /* LAC */