05cc5fdc88b91c8f7160b248e6b40776e829edd1
3 char const *cvs_id_ppp
= "$Id: ppp.c,v 1.69 2005-08-11 05:50:49 bodea Exp $";
11 #include "constants.h"
17 extern tunnelt
*tunnel
;
18 extern sessiont
*session
;
19 extern radiust
*radius
;
21 extern char hostname
[];
22 extern uint32_t eth_tx
;
23 extern time_t time_now
;
24 extern configt
*config
;
26 static int add_lcp_auth(uint8_t *b
, int size
, int authtype
);
28 // Process PAP messages
29 void processpap(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
38 LOG_HEX(5, "PAP", p
, l
);
41 LOG(1, s
, t
, "Short PAP %u bytes\n", l
);
42 STAT(tunnel_rx_errors
);
43 sessionshutdown(s
, "Short PAP packet.", 3, 0);
47 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
49 LOG(1, s
, t
, "Length mismatch PAP %u/%u\n", hl
, l
);
50 STAT(tunnel_rx_errors
);
51 sessionshutdown(s
, "PAP length mismatch.", 3, 0);
58 LOG(1, s
, t
, "Unexpected PAP code %d\n", *p
);
59 STAT(tunnel_rx_errors
);
60 sessionshutdown(s
, "Unexpected PAP code.", 3, 0);
64 if (session
[s
].ppp
.phase
!= Authenticate
)
66 LOG(2, s
, t
, "PAP ignored in %s phase\n", ppp_phase(session
[s
].ppp
.phase
));
73 user
[0] = pass
[0] = 0;
74 if (*b
&& *b
< sizeof(user
))
76 memcpy(user
, b
+ 1, *b
);
79 if (*b
&& *b
< sizeof(pass
))
81 memcpy(pass
, b
+ 1, *b
);
85 LOG(3, s
, t
, "PAP login %s/%s\n", user
, pass
);
89 if (session
[s
].ip
|| !r
)
91 // respond now, either no RADIUS available or already authenticated
92 uint8_t b
[MAXCONTROL
];
94 uint8_t *p
= makeppp(b
, sizeof(b
), 0, 0, s
, t
, PPPPAP
);
100 *p
= 3; // cant authorise
102 *(uint16_t *) (p
+ 2) = htons(5); // length
103 p
[4] = 0; // no message
104 tunnelsend(b
, 5 + (p
- b
), t
); // send it
108 LOG(3, s
, t
, "Already an IP allocated: %s (%d)\n",
109 fmtaddr(htonl(session
[s
].ip
), 0), session
[s
].ip_pool_index
);
113 LOG(1, s
, t
, "No RADIUS session available to authenticate session...\n");
114 sessionshutdown(s
, "No free RADIUS sessions.", 4, 0);
119 // Run PRE_AUTH plugins
120 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], strdup(user
), strdup(pass
), PPPPAP
, 1 };
121 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
122 if (!packet
.continue_auth
)
124 LOG(3, s
, t
, "A plugin rejected PRE_AUTH\n");
125 if (packet
.username
) free(packet
.username
);
126 if (packet
.password
) free(packet
.password
);
130 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
131 strncpy(radius
[r
].pass
, packet
.password
, sizeof(radius
[r
].pass
) - 1);
133 free(packet
.username
);
134 free(packet
.password
);
137 LOG(3, s
, t
, "Sending login for %s/%s to RADIUS\n", user
, pass
);
138 radiussend(r
, RADIUSAUTH
);
142 // Process CHAP messages
143 void processchap(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
150 LOG_HEX(5, "CHAP", p
, l
);
151 r
= sess_local
[s
].radius
;
154 LOG(1, s
, t
, "Unexpected CHAP message\n");
155 STAT(tunnel_rx_errors
);
161 LOG(1, s
, t
, "Short CHAP %u bytes\n", l
);
162 STAT(tunnel_rx_errors
);
163 sessionshutdown(s
, "Short CHAP packet.", 3, 0);
167 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
169 LOG(1, s
, t
, "Length mismatch CHAP %u/%u\n", hl
, l
);
170 STAT(tunnel_rx_errors
);
171 sessionshutdown(s
, "CHAP length mismatch.", 3, 0);
178 LOG(1, s
, t
, "Unexpected CHAP response code %d\n", *p
);
179 STAT(tunnel_rx_errors
);
180 sessionshutdown(s
, "CHAP length mismatch.", 3, 0);
184 if (session
[s
].ppp
.phase
!= Authenticate
)
186 LOG(2, s
, t
, "CHAP ignored in %s phase\n", ppp_phase(session
[s
].ppp
.phase
));
190 if (p
[1] != radius
[r
].id
)
192 LOG(1, s
, t
, "Wrong CHAP response ID %d (should be %d) (%d)\n", p
[1], radius
[r
].id
, r
);
193 STAT(tunnel_rx_errors
);
194 sessionshutdown(s
, "Unexpected CHAP response ID.", 3, 0);
198 if (l
< 5 || p
[4] != 16)
200 LOG(1, s
, t
, "Bad CHAP response length %d\n", l
< 5 ? -1 : p
[4]);
201 STAT(tunnel_rx_errors
);
202 sessionshutdown(s
, "Bad CHAP response length.", 3, 0);
208 if (l
< 16 || l
- 16 >= sizeof(session
[s
].user
))
210 LOG(1, s
, t
, "CHAP user too long %d\n", l
- 16);
211 STAT(tunnel_rx_errors
);
212 sessionshutdown(s
, "CHAP username too long.", 3, 0);
216 // Run PRE_AUTH plugins
218 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], NULL
, NULL
, PPPCHAP
, 1 };
220 packet
.password
= calloc(17, 1);
221 memcpy(packet
.password
, p
, 16);
226 packet
.username
= calloc(l
+ 1, 1);
227 memcpy(packet
.username
, p
, l
);
229 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
230 if (!packet
.continue_auth
)
232 LOG(3, s
, t
, "A plugin rejected PRE_AUTH\n");
233 if (packet
.username
) free(packet
.username
);
234 if (packet
.password
) free(packet
.password
);
238 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
239 memcpy(radius
[r
].pass
, packet
.password
, 16);
241 free(packet
.username
);
242 free(packet
.password
);
246 LOG(3, s
, t
, "CHAP login %s\n", session
[s
].user
);
247 radiussend(r
, RADIUSAUTH
);
250 static void dumplcp(uint8_t *p
, int l
)
253 uint8_t *o
= (p
+ 4);
255 LOG_HEX(5, "PPP LCP Packet", p
, l
);
256 LOG(4, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p
, ppp_code((int)*p
), ntohs( ((uint16_t *) p
)[1]) );
257 LOG(4, 0, 0, "Length: %d\n", l
);
258 if (*p
!= ConfigReq
&& *p
!= ConfigRej
&& *p
!= ConfigAck
)
267 LOG(4, 0, 0, " Option length is %d...\n", length
);
272 LOG(4, 0, 0, " Option type is 0...\n");
279 case 1: // Maximum-Receive-Unit
281 LOG(4, 0, 0, " %s %d\n", ppp_lcp_option(type
), ntohs(*(uint16_t *)(o
+ 2)));
283 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
285 case 2: // Async-Control-Character-Map
288 uint32_t asyncmap
= ntohl(*(uint32_t *)(o
+ 2));
289 LOG(4, 0, 0, " %s %x\n", ppp_lcp_option(type
), asyncmap
);
292 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
294 case 3: // Authentication-Protocol
297 int proto
= ntohs(*(uint16_t *)(o
+ 2));
298 LOG(4, 0, 0, " %s 0x%x (%s)\n", ppp_lcp_option(type
), proto
,
299 proto
== PPPPAP
? "PAP" : "UNSUPPORTED");
301 else if (length
== 5)
303 int proto
= ntohs(*(uint16_t *)(o
+ 2));
304 int algo
= *(uint8_t *)(o
+ 4);
305 LOG(4, 0, 0, " %s 0x%x 0x%x (%s)\n", ppp_lcp_option(type
), proto
, algo
,
306 (proto
== PPPCHAP
&& algo
== 5) ? "CHAP MD5" : "UNSUPPORTED");
309 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
311 case 4: // Quality-Protocol
313 uint32_t qp
= ntohl(*(uint32_t *)(o
+ 2));
314 LOG(4, 0, 0, " %s %x\n", ppp_lcp_option(type
), qp
);
317 case 5: // Magic-Number
320 uint32_t magicno
= ntohl(*(uint32_t *)(o
+ 2));
321 LOG(4, 0, 0, " %s %x\n", ppp_lcp_option(type
), magicno
);
324 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
326 case 7: // Protocol-Field-Compression
327 case 8: // Address-And-Control-Field-Compression
328 LOG(4, 0, 0, " %s\n", ppp_lcp_option(type
));
331 LOG(2, 0, 0, " Unknown PPP LCP Option type %d\n", type
);
339 void lcp_open(sessionidt s
, tunnelidt t
)
341 // transition to Authentication or Network phase:
342 session
[s
].ppp
.phase
= sess_local
[s
].lcp_authtype
? Authenticate
: Network
;
345 change_state(s
, lcp
, Opened
);
347 if (session
[s
].ppp
.phase
== Authenticate
)
349 if (sess_local
[s
].lcp_authtype
== AUTHCHAP
)
356 change_state(s
, ipcp
, RequestSent
);
357 // move to passive state for IPv6 (if configured), CCP
358 if (config
->ipv6_prefix
.s6_addr
[0])
359 change_state(s
, ipv6cp
, Stopped
);
361 change_state(s
, ipv6cp
, Closed
);
363 change_state(s
, ccp
, Stopped
);
367 static void lcp_restart(sessionidt s
)
369 session
[s
].ppp
.phase
= Establish
;
371 change_state(s
, ipcp
, Dead
);
372 change_state(s
, ipv6cp
, Dead
);
373 change_state(s
, ccp
, Dead
);
376 static uint8_t *ppp_rej(sessionidt s
, uint8_t *buf
, size_t blen
, uint16_t mtype
,
377 uint8_t **response
, uint8_t *queued
, uint8_t *packet
, uint8_t *option
)
379 if (!*response
|| **response
!= ConfigRej
)
381 queued
= *response
= makeppp(buf
, blen
, packet
, 2, s
, session
[s
].tunnel
, mtype
);
389 if ((queued
- buf
+ option
[1]) > blen
)
391 LOG(2, s
, session
[s
].tunnel
, "PPP overflow for ConfigRej (proto %u, option %u).\n", mtype
, *option
);
395 memcpy(queued
, option
, option
[1]);
396 return queued
+ option
[1];
399 static uint8_t *ppp_nak(sessionidt s
, uint8_t *buf
, size_t blen
, uint16_t mtype
,
400 uint8_t **response
, uint8_t *queued
, uint8_t *packet
, uint8_t *option
,
401 uint8_t *value
, size_t vlen
)
406 case PPPLCP
: nak_sent
= &sess_local
[s
].lcp
.nak_sent
; break;
407 case PPPIPCP
: nak_sent
= &sess_local
[s
].ipcp
.nak_sent
; break;
408 case PPPIPV6CP
: nak_sent
= &sess_local
[s
].ipv6cp
.nak_sent
; break;
409 default: return 0; // ?
412 if (*response
&& **response
!= ConfigNak
)
414 if (*nak_sent
< config
->ppp_max_failure
) // reject queued
417 return ppp_rej(s
, buf
, blen
, mtype
, response
, 0, packet
, option
);
422 if (*nak_sent
>= config
->ppp_max_failure
)
423 return ppp_rej(s
, buf
, blen
, mtype
, response
, 0, packet
, option
);
425 queued
= *response
= makeppp(buf
, blen
, packet
, 2, s
, session
[s
].tunnel
, mtype
);
434 if ((queued
- buf
+ vlen
+ 2) > blen
)
436 LOG(2, s
, session
[s
].tunnel
, "PPP overflow for ConfigNak (proto %u, option %u).\n", mtype
, *option
);
441 *queued
++ = vlen
+ 2;
442 memcpy(queued
, value
, vlen
);
443 return queued
+ vlen
;
446 // Process LCP messages
447 void processlcp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
449 uint8_t b
[MAXCONTROL
];
451 uint32_t magicno
= 0;
456 LOG_HEX(5, "LCP", p
, l
);
459 LOG(1, s
, t
, "Short LCP %d bytes\n", l
);
460 STAT(tunnel_rx_errors
);
464 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
466 LOG(1, s
, t
, "Length mismatch LCP %u/%u\n", hl
, l
);
467 STAT(tunnel_rx_errors
);
472 if (session
[s
].die
) // going down...
475 LOG(*p
== EchoReq
? 4 : 3, s
, t
, "LCP: recv %s\n", ppp_code(*p
));
476 if (config
->debug
> 3) dumplcp(p
, l
);
481 uint8_t *o
= (p
+ 4);
489 if (length
== 0 || type
== 0 || x
< length
) break;
492 case 3: // Authentication-Protocol
494 int proto
= ntohs(*(uint16_t *)(o
+ 2));
497 else if (proto
== PPPCHAP
&& *(o
+ 4) == 5)
507 if (!session
[s
].ip
&& authtype
)
508 sess_local
[s
].lcp_authtype
= authtype
;
510 switch (session
[s
].ppp
.lcp
)
513 initialise_restart_count(s
, lcp
);
514 change_state(s
, lcp
, AckReceived
);
519 LOG(2, s
, t
, "LCP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.lcp
));
520 if (session
[s
].ppp
.lcp
== Opened
)
523 sendlcp(s
, t
, sess_local
[s
].lcp_authtype
);
524 change_state(s
, lcp
, RequestSent
);
532 LOG(2, s
, t
, "LCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.lcp
));
535 else if (*p
== ConfigReq
)
538 uint8_t *o
= (p
+ 4);
539 uint8_t *response
= 0;
540 static uint8_t asyncmap
[4] = { 0, 0, 0, 0 }; // all zero
541 static uint8_t authproto
[5];
548 if (length
== 0 || type
== 0 || x
< length
) break;
551 case 1: // Maximum-Receive-Unit
552 session
[s
].mru
= ntohs(*(uint16_t *)(o
+ 2));
555 case 2: // Async-Control-Character-Map
556 if (!ntohl(*(uint32_t *)(o
+ 2))) // all bits zero is OK
559 LOG(3, s
, t
, " Remote requesting asyncmap. Rejecting.\n");
560 q
= ppp_nak(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
, asyncmap
, sizeof(asyncmap
));
563 case 3: // Authentication-Protocol
565 int proto
= ntohs(*(uint16_t *)(o
+ 2));
566 char proto_name
[] = "0x0000";
571 if (config
->radius_authtypes
& AUTHPAP
)
573 sess_local
[s
].lcp_authtype
= AUTHPAP
;
577 strcpy(proto_name
, "PAP");
579 else if (proto
== PPPCHAP
)
581 if (config
->radius_authtypes
& AUTHCHAP
582 && *(o
+ 4) == 5) // MD5
584 sess_local
[s
].lcp_authtype
= AUTHCHAP
;
588 strcpy(proto_name
, "CHAP");
591 sprintf(proto_name
, "%#4.4x", proto
);
593 LOG(3, s
, t
, " Remote requesting %s authentication. Rejecting.\n", proto_name
);
595 alen
= add_lcp_auth(authproto
, sizeof(authproto
), config
->radius_authprefer
);
596 if (alen
< 2) break; // paranoia
598 q
= ppp_nak(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
, authproto
+ 2, alen
- 2);
599 if (q
&& *response
== ConfigNak
&&
600 config
->radius_authtypes
!= config
->radius_authprefer
)
603 alen
= add_lcp_auth(authproto
, sizeof(authproto
), config
->radius_authtypes
& ~config
->radius_authprefer
);
605 q
= ppp_nak(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
, authproto
+ 2, alen
- 2);
612 case 5: // Magic-Number
613 magicno
= ntohl(*(uint32_t *)(o
+ 2));
616 case 4: // Quality-Protocol
617 case 7: // Protocol-Field-Compression
618 case 8: // Address-And-Control-Field-Compression
621 default: // Reject any unknown options
622 LOG(3, s
, t
, " Rejecting unknown PPP LCP option %d\n", type
);
623 q
= ppp_rej(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
);
631 l
= q
- response
; // LCP packet length
632 *((uint16_t *) (response
+ 2)) = htons(l
); // update header
636 // Send packet back as ConfigAck
637 response
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPLCP
);
638 if (!response
) return;
639 *response
= ConfigAck
;
642 switch (session
[s
].ppp
.lcp
)
645 response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPLCP
);
646 if (!response
) return;
647 *response
= TerminateAck
;
648 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
652 initialise_restart_count(s
, lcp
);
653 sendlcp(s
, t
, sess_local
[s
].lcp_authtype
);
654 if (*response
== ConfigAck
)
655 change_state(s
, lcp
, AckSent
);
657 change_state(s
, lcp
, RequestSent
);
662 if (*response
== ConfigAck
)
663 change_state(s
, lcp
, AckSent
);
668 if (*response
== ConfigAck
)
675 sendlcp(s
, t
, sess_local
[s
].lcp_authtype
);
679 if (*response
== ConfigAck
)
680 change_state(s
, lcp
, AckSent
);
682 change_state(s
, lcp
, RequestSent
);
687 LOG(2, s
, t
, "LCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.lcp
));
691 LOG(3, s
, t
, "LCP: send %s\n", ppp_code(*response
));
692 if (config
->debug
> 3) dumplcp(response
, l
);
694 tunnelsend(b
, l
+ (response
- b
), t
);
696 else if (*p
== ConfigNak
)
699 uint8_t *o
= (p
+ 4);
707 if (length
== 0 || type
== 0 || x
< length
) break;
710 case 1: // Maximum-Receive-Unit
711 session
[s
].mru
= ntohs(*(uint16_t *)(o
+ 2));
712 LOG(3, s
, t
, " Remote requested MRU of %u\n", session
[s
].mru
);
715 case 3: // Authentication-Protocol
720 int proto
= ntohs(*(uint16_t *)(o
+ 2));
723 authtype
= config
->radius_authtypes
& AUTHPAP
;
724 LOG(3, s
, t
, " Remote requested PAP authentication...%sing\n",
725 authtype
? "accept" : "reject");
727 else if (proto
== PPPCHAP
&& *(o
+ 4) == 5)
729 authtype
= config
->radius_authtypes
& AUTHCHAP
;
730 LOG(3, s
, t
, " Remote requested CHAP authentication...%sing\n",
731 authtype
? "accept" : "reject");
735 LOG(3, s
, t
, " Rejecting unsupported authentication %#4x\n",
743 LOG(2, s
, t
, " Remote NAKed LCP type %u?\n", type
);
752 sessionshutdown(s
, "Unsupported authentication.", 3, 0);
757 sess_local
[s
].lcp_authtype
= authtype
;
759 switch (session
[s
].ppp
.lcp
)
764 uint8_t *response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPLCP
);
765 if (!response
) return;
766 *response
= TerminateAck
;
767 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
768 tunnelsend(b
, l
+ (response
- b
), t
);
774 initialise_restart_count(s
, lcp
);
775 sendlcp(s
, t
, sess_local
[s
].lcp_authtype
);
779 LOG(2, s
, t
, "LCP: ConfigNak in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.lcp
));
780 sendlcp(s
, t
, sess_local
[s
].lcp_authtype
);
785 sendlcp(s
, t
, sess_local
[s
].lcp_authtype
);
789 LOG(2, s
, t
, "LCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.lcp
));
793 else if (*p
== TerminateReq
)
795 *p
= TerminateAck
; // close
796 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPLCP
);
798 tunnelsend(b
, l
+ (q
- b
), t
); // send it
799 sessionshutdown(s
, "Remote end closed connection.", 3, 0);
801 else if (*p
== TerminateAck
)
803 sessionshutdown(s
, "Connection closed.", 3, 0);
805 else if (*p
== ProtocolRej
)
807 if (*(uint16_t *) (p
+4) == htons(PPPIPV6CP
))
809 LOG(3, s
, t
, "IPv6 rejected\n");
810 change_state(s
, ipv6cp
, Closed
);
814 LOG(1, s
, t
, "Unexpected LCP protocol reject 0x%X\n",
815 ntohs(*(uint16_t *) (p
+4)));
816 STAT(tunnel_rx_errors
);
819 else if (*p
== EchoReq
)
821 *p
= EchoReply
; // reply
822 *(uint32_t *) (p
+ 4) = htonl(session
[s
].magic
); // our magic number
823 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPLCP
);
825 tunnelsend(b
, l
+ (q
- b
), t
); // send it
827 else if (*p
== EchoReply
)
829 // Ignore it, last_packet time is set earlier than this.
834 int mru
= session
[s
].mru
;
838 if (l
> mru
) l
= mru
;
841 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPLCP
);
844 LOG(3, s
, t
, "Unexpected LCP code %s\n", ppp_code(code
));
845 tunnelsend(b
, l
+ (q
- b
), t
);
849 static void ipcp_open(sessionidt s
, tunnelidt t
)
851 LOG(3, s
, t
, "IPCP: Opened, session is now active\n");
853 change_state(s
, ipcp
, Opened
);
855 if (!session
[s
].walled_garden
)
857 uint16_t r
= radiusnew(s
);
859 radiussend(r
, RADIUSSTART
); // send radius start
862 // start IPv6 if configured and still in passive state
863 if (session
[s
].ppp
.ipv6cp
== Stopped
)
866 change_state(s
, ipv6cp
, RequestSent
);
870 // Process IPCP messages
871 void processipcp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
873 uint8_t b
[MAXCONTROL
];
879 LOG_HEX(5, "IPCP", p
, l
);
882 LOG(1, s
, t
, "Short IPCP %d bytes\n", l
);
883 STAT(tunnel_rx_errors
);
887 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
889 LOG(1, s
, t
, "Length mismatch IPCP %u/%u\n", hl
, l
);
890 STAT(tunnel_rx_errors
);
895 if (session
[s
].ppp
.phase
< Network
)
897 LOG(2, s
, t
, "IPCP %s ignored in %s phase\n", ppp_code(*p
), ppp_phase(session
[s
].ppp
.phase
));
903 switch (session
[s
].ppp
.ipcp
)
906 initialise_restart_count(s
, ipcp
);
907 change_state(s
, ipcp
, AckReceived
);
912 LOG(2, s
, t
, "IPCP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.ipcp
));
914 change_state(s
, ipcp
, RequestSent
);
922 LOG(2, s
, t
, "IPCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipcp
));
925 else if (*p
== ConfigReq
)
927 uint8_t *response
= 0;
933 LOG(3, s
, t
, "IPCP: ConfigReq received\n");
939 case 3: // ip address
940 gotip
++; // seen address
941 if (o
[1] != 6 || o
[1] > length
) return;
943 addr
= htonl(session
[s
].ip
);
944 if (memcmp(o
+ 2, &addr
, (sizeof addr
)))
946 q
= ppp_nak(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
, (uint8_t *) &addr
, sizeof(addr
));
947 if (!q
|| *response
== ConfigRej
)
949 sessionshutdown(s
, "Can't negotiate IPCP.", 3, 0);
956 case 129: // primary DNS
957 if (o
[1] != 6 || o
[1] > length
) return;
959 addr
= htonl(session
[s
].dns1
);
960 if (memcmp(o
+ 2, &addr
, (sizeof addr
)))
962 q
= ppp_nak(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
, (uint8_t *) &addr
, sizeof(addr
));
968 case 131: // secondary DNS
969 if (o
[1] != 6 || o
[1] > length
) return;
971 addr
= htonl(session
[s
].dns1
);
972 if (memcmp(o
+ 2, &addr
, sizeof(addr
)))
974 q
= ppp_nak(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
, (uint8_t *) &addr
, sizeof(addr
));
981 LOG(2, s
, t
, " Rejecting PPP IPCP Option type %d\n", *o
);
982 q
= ppp_rej(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
);
992 l
= q
- response
; // IPCP packet length
993 *((uint16_t *) (response
+ 2)) = htons(l
); // update header
997 // Send packet back as ConfigAck
998 response
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPCP
);
999 if (!response
) return;
1000 *response
= ConfigAck
;
1004 LOG(1, s
, t
, "No IP in IPCP request\n");
1005 STAT(tunnel_rx_errors
);
1009 switch (session
[s
].ppp
.ipcp
)
1012 response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPIPCP
);
1013 if (!response
) return;
1014 *response
= TerminateAck
;
1015 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
1019 initialise_restart_count(s
, ipcp
);
1021 if (*response
== ConfigAck
)
1022 change_state(s
, ipcp
, AckSent
);
1024 change_state(s
, ipcp
, RequestSent
);
1029 if (*response
== ConfigAck
)
1030 change_state(s
, ipcp
, AckSent
);
1035 if (*response
== ConfigAck
)
1041 initialise_restart_count(s
, ipcp
);
1046 if (*response
== ConfigAck
)
1047 change_state(s
, ipcp
, AckSent
);
1049 change_state(s
, ipcp
, RequestSent
);
1054 LOG(2, s
, t
, "IPCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipcp
));
1058 LOG(3, s
, t
, "IPCP: Sending %s\n", ppp_code(*response
));
1059 tunnelsend(b
, l
+ (response
- b
), t
);
1061 else if (*p
== TerminateReq
)
1063 LOG(3, s
, t
, "IPCP: Received TerminateReq. Sending TerminateAck\n");
1065 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPCP
);
1067 tunnelsend(b
, l
+ (q
- b
), t
);
1068 change_state(s
, ipcp
, Stopped
);
1073 int mru
= session
[s
].mru
;
1077 if (l
> mru
) l
= mru
;
1080 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPCP
);
1083 LOG(3, s
, t
, "Unexpected IPCP code %s\n", ppp_code(code
));
1084 tunnelsend(b
, l
+ (q
- b
), t
);
1088 static void ipv6cp_open(sessionidt s
, tunnelidt t
)
1090 LOG(3, s
, t
, "IPV6CP: Opened\n");
1092 change_state(s
, ipv6cp
, Opened
);
1093 if (session
[s
].ipv6prefixlen
)
1094 route6set(s
, session
[s
].ipv6route
, session
[s
].ipv6prefixlen
, 1);
1096 // Send an initial RA (TODO: Should we send these regularly?)
1097 send_ipv6_ra(s
, t
, NULL
);
1100 // Process IPV6CP messages
1101 void processipv6cp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1103 uint8_t b
[MAXCONTROL
];
1107 CSTAT(processipv6cp
);
1109 LOG_HEX(5, "IPV6CP", p
, l
);
1112 LOG(1, s
, t
, "Short IPV6CP %d bytes\n", l
);
1113 STAT(tunnel_rx_errors
);
1117 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
1119 LOG(1, s
, t
, "Length mismatch IPV6CP %u/%u\n", hl
, l
);
1120 STAT(tunnel_rx_errors
);
1125 if (session
[s
].ppp
.phase
< Network
)
1127 LOG(2, s
, t
, "IPV6CP %s ignored in %s phase\n", ppp_code(*p
), ppp_phase(session
[s
].ppp
.phase
));
1131 if (!config
->ipv6_prefix
.s6_addr
[0])
1133 LOG(2, s
, t
, "IPV6CP: %s rejected (not configured)\n", ppp_code(*p
));
1135 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPV6CP
);
1137 tunnelsend(b
, l
+ (q
- b
), t
);
1143 LOG(3, s
, t
, "IPV6CP: no IPv4 address (IPCP in state %s)\n", ppp_state(session
[s
].ppp
.ipcp
));
1144 return; // need IPCP to complete...
1147 if (*p
== ConfigAck
)
1149 switch (session
[s
].ppp
.ipv6cp
)
1152 initialise_restart_count(s
, ipv6cp
);
1153 change_state(s
, ipv6cp
, AckReceived
);
1158 LOG(2, s
, t
, "IPV6CP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.ipv6cp
));
1160 change_state(s
, ipv6cp
, RequestSent
);
1168 LOG(2, s
, t
, "IPV6CP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipv6cp
));
1171 else if (*p
== ConfigReq
)
1173 uint8_t *response
= 0;
1179 LOG(3, s
, t
, "IPV6CP: ConfigReq received\n");
1185 case 1: // interface identifier
1186 gotip
++; // seen address
1187 if (o
[1] != 10 || o
[1] > length
) return;
1189 *(uint32_t *) ident
= htonl(session
[s
].ip
);
1190 *(uint32_t *) (ident
+ 4) = 0;
1192 if (memcmp(o
+ 2, ident
, sizeof(ident
)))
1194 q
= ppp_nak(s
, b
, sizeof(b
), PPPIPV6CP
, &response
, q
, p
, o
, ident
, sizeof(ident
));
1201 LOG(2, s
, t
, " Rejecting PPP IPV6CP Option type %d\n", *o
);
1202 q
= ppp_rej(s
, b
, sizeof(b
), PPPIPV6CP
, &response
, q
, p
, o
);
1212 l
= q
- response
; // IPV6CP packet length
1213 *((uint16_t *) (response
+ 2)) = htons(l
); // update header
1217 // Send packet back as ConfigAck
1218 response
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPV6CP
);
1219 if (!response
) return;
1220 *response
= ConfigAck
;
1224 LOG(1, s
, t
, "No interface identifier in IPV6CP request\n");
1225 STAT(tunnel_rx_errors
);
1229 switch (session
[s
].ppp
.ipv6cp
)
1232 response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPIPV6CP
);
1233 if (!response
) return;
1234 *response
= TerminateAck
;
1235 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
1239 initialise_restart_count(s
, ipv6cp
);
1241 if (*response
== ConfigAck
)
1242 change_state(s
, ipv6cp
, AckSent
);
1244 change_state(s
, ipv6cp
, RequestSent
);
1249 if (*response
== ConfigAck
)
1250 change_state(s
, ipv6cp
, AckSent
);
1255 if (*response
== ConfigAck
)
1261 initialise_restart_count(s
, ipv6cp
);
1266 if (*response
== ConfigAck
)
1267 change_state(s
, ipv6cp
, AckSent
);
1269 change_state(s
, ipv6cp
, RequestSent
);
1274 LOG(2, s
, t
, "IPV6CP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipv6cp
));
1278 LOG(3, s
, t
, "IPV6CP: Sending %s\n", ppp_code(*response
));
1279 tunnelsend(b
, l
+ (response
- b
), t
);
1281 else if (*p
== TerminateReq
)
1283 LOG(3, s
, t
, "IPV6CP: Received TerminateReq. Sending TerminateAck\n");
1285 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPV6CP
);
1287 tunnelsend(b
, l
+ (q
- b
), t
);
1288 change_state(s
, ipv6cp
, Stopped
);
1293 int mru
= session
[s
].mru
;
1297 if (l
> mru
) l
= mru
;
1300 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPV6CP
);
1303 LOG(3, s
, t
, "Unexpected IPV6CP code %s\n", ppp_code(code
));
1304 tunnelsend(b
, l
+ (q
- b
), t
);
1308 // process IP packet received
1310 // This MUST be called with at least 4 byte behind 'p'.
1311 // (i.e. this routine writes to p[-4]).
1312 void processipin(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1318 LOG_HEX(5, "IP", p
, l
);
1320 ip
= ntohl(*(uint32_t *)(p
+ 12));
1324 LOG(1, s
, t
, "IP packet too long %d\n", l
);
1325 STAT(tunnel_rx_errors
);
1329 if (session
[s
].ppp
.phase
!= Network
|| session
[s
].ppp
.ipcp
!= Opened
)
1332 // no spoof (do sessionbyip to handled statically routed subnets)
1333 if (ip
!= session
[s
].ip
&& sessionbyip(htonl(ip
)) != s
)
1335 LOG(5, s
, t
, "Dropping packet with spoofed IP %s\n", fmtaddr(htonl(ip
), 0));
1339 // run access-list if any
1340 if (session
[s
].filter_in
&& !ip_filter(p
, l
, session
[s
].filter_in
- 1))
1343 // Add on the tun header
1345 *(uint32_t *) p
= htonl(PKTIP
);
1348 // Are we throttled and a slave?
1349 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) {
1350 // Pass it to the master for handling.
1351 master_throttle_packet(session
[s
].tbf_in
, p
, l
);
1355 // Are we throttled and a master??
1356 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) {
1357 // Actually handle the throttled packets.
1358 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
1363 if (tun_write(p
, l
) < 0)
1365 STAT(tun_tx_errors
);
1366 LOG(0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
1367 l
, strerror(errno
), tunfd
, p
);
1375 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
1377 // Snooping this session
1378 snoop_send_packet(p
, l
, session
[s
].snoop_ip
, session
[s
].snoop_port
);
1381 increment_counter(&session
[s
].cin
, &session
[s
].cin_wrap
, l
);
1382 session
[s
].cin_delta
+= l
;
1385 sess_local
[s
].cin
+= l
;
1386 sess_local
[s
].pin
++;
1390 STAT(tun_tx_packets
);
1391 INC_STAT(tun_tx_bytes
, l
);
1394 // process IPv6 packet received
1396 // This MUST be called with at least 4 byte behind 'p'.
1397 // (i.e. this routine writes to p[-4]).
1398 void processipv6in(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1403 CSTAT(processipv6in
);
1405 LOG_HEX(5, "IPv6", p
, l
);
1407 ip
= *(struct in6_addr
*) (p
+ 8);
1408 ipv4
= ntohl(*(uint32_t *)(p
+ 16));
1412 LOG(1, s
, t
, "IP packet too long %d\n", l
);
1413 STAT(tunnel_rx_errors
);
1417 if (session
[s
].ppp
.phase
!= Network
|| session
[s
].ppp
.ipv6cp
!= Opened
)
1421 if (ipv4
!= session
[s
].ip
&& memcmp(&config
->ipv6_prefix
, &ip
, 8) && sessionbyipv6(ip
) != s
)
1423 char str
[INET6_ADDRSTRLEN
];
1424 LOG(5, s
, t
, "Dropping packet with spoofed IP %s\n",
1425 inet_ntop(AF_INET6
, &ip
, str
, INET6_ADDRSTRLEN
));
1429 // Check if it's a Router Solicition message.
1430 if (*(p
+ 6) == 58 && *(p
+ 7) == 255 && *(p
+ 24) == 0xFF && *(p
+ 25) == 2 &&
1431 *(uint32_t *)(p
+ 26) == 0 && *(uint32_t *)(p
+ 30) == 0 &&
1432 *(uint32_t *)(p
+ 34) == 0 &&
1433 *(p
+ 38) == 0 && *(p
+ 39) == 2 && *(p
+ 40) == 133) {
1434 LOG(3, s
, t
, "Got IPv6 RS\n");
1435 send_ipv6_ra(s
, t
, &ip
);
1439 // Add on the tun header
1441 *(uint32_t *) p
= htonl(PKTIPV6
);
1444 // Are we throttled and a slave?
1445 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) {
1446 // Pass it to the master for handling.
1447 master_throttle_packet(session
[s
].tbf_in
, p
, l
);
1451 // Are we throttled and a master??
1452 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) {
1453 // Actually handle the throttled packets.
1454 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
1459 if (tun_write(p
, l
) < 0)
1461 STAT(tun_tx_errors
);
1462 LOG(0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
1463 l
, strerror(errno
), tunfd
, p
);
1471 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
1473 // Snooping this session
1474 snoop_send_packet(p
, l
, session
[s
].snoop_ip
, session
[s
].snoop_port
);
1477 increment_counter(&session
[s
].cin
, &session
[s
].cin_wrap
, l
);
1478 session
[s
].cin_delta
+= l
;
1481 sess_local
[s
].cin
+= l
;
1482 sess_local
[s
].pin
++;
1486 STAT(tun_tx_packets
);
1487 INC_STAT(tun_tx_bytes
, l
);
1491 // Helper routine for the TBF filters.
1492 // Used to send queued data in from the user.
1494 void send_ipin(sessionidt s
, uint8_t *buf
, int len
)
1496 LOG_HEX(5, "IP in throttled", buf
, len
);
1498 if (write(tunfd
, buf
, len
) < 0)
1500 STAT(tun_tx_errors
);
1501 LOG(0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
1502 len
, strerror(errno
), tunfd
, buf
);
1510 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
1512 // Snooping this session
1513 snoop_send_packet(buf
, len
, session
[s
].snoop_ip
, session
[s
].snoop_port
);
1516 // Increment packet counters
1517 increment_counter(&session
[s
].cin
, &session
[s
].cin_wrap
, len
);
1518 session
[s
].cin_delta
+= len
;
1521 sess_local
[s
].cin
+= len
;
1522 sess_local
[s
].pin
++;
1526 STAT(tun_tx_packets
);
1527 INC_STAT(tun_tx_bytes
, len
- 4);
1531 // Process CCP messages
1532 void processccp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1534 uint8_t b
[MAXCONTROL
];
1539 LOG_HEX(5, "CCP", p
, l
);
1541 if (session
[s
].ppp
.phase
< Network
)
1543 LOG(2, s
, t
, "CCP %s ignored in %s phase\n", ppp_code(*p
), ppp_phase(session
[s
].ppp
.phase
));
1549 LOG(1, s
, t
, "Short CCP packet\n");
1550 STAT(tunnel_rx_errors
);
1553 if (*p
== ConfigAck
)
1555 switch (session
[s
].ppp
.ccp
)
1558 initialise_restart_count(s
, ccp
);
1559 change_state(s
, ccp
, AckReceived
);
1564 LOG(2, s
, t
, "CCP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.ccp
));
1566 change_state(s
, ccp
, RequestSent
);
1570 LOG(3, s
, t
, "CCP: Opened\n");
1571 change_state(s
, ccp
, Opened
);
1575 LOG(2, s
, t
, "CCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ccp
));
1578 else if (*p
== ConfigReq
)
1580 if (l
< 6) // accept no compression
1582 else // compression requested--reject
1585 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPCCP
);
1588 switch (session
[s
].ppp
.ccp
)
1591 q
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPCCP
);
1594 *((uint16_t *) (q
+ 2)) = htons(l
= 4);
1598 initialise_restart_count(s
, ccp
);
1600 if (*q
== ConfigAck
)
1601 change_state(s
, ccp
, AckSent
);
1603 change_state(s
, ccp
, RequestSent
);
1608 if (*q
== ConfigAck
)
1609 change_state(s
, ccp
, AckSent
);
1614 if (*q
== ConfigAck
)
1615 change_state(s
, ccp
, Opened
);
1620 initialise_restart_count(s
, ccp
);
1625 if (*q
== ConfigAck
)
1626 change_state(s
, ccp
, AckSent
);
1628 change_state(s
, ccp
, RequestSent
);
1633 LOG(2, s
, t
, "CCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ccp
));
1637 LOG(3, s
, t
, "CCP: Sending %s\n", ppp_code(*q
));
1638 tunnelsend(b
, l
+ (q
- b
), t
);
1640 else if (*p
== TerminateReq
)
1642 LOG(3, s
, t
, "CCP: Received TerminateReq. Sending TerminateAck\n");
1644 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPCCP
);
1646 tunnelsend(b
, l
+ (q
- b
), t
);
1647 change_state(s
, ccp
, Stopped
);
1652 int mru
= session
[s
].mru
;
1656 if (l
> mru
) l
= mru
;
1659 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPCCP
);
1662 LOG(3, s
, t
, "Unexpected CCP code %s\n", ppp_code(code
));
1663 tunnelsend(b
, l
+ (q
- b
), t
);
1667 // send a CHAP challenge
1668 void sendchap(sessionidt s
, tunnelidt t
)
1670 uint8_t b
[MAXCONTROL
];
1679 LOG(1, s
, t
, "No RADIUS to send challenge\n");
1680 STAT(tunnel_tx_errors
);
1684 LOG(1, s
, t
, "Send CHAP challenge\n");
1686 radius
[r
].chap
= 1; // CHAP not PAP
1688 if (radius
[r
].state
!= RADIUSCHAP
)
1691 radius
[r
].state
= RADIUSCHAP
;
1692 radius
[r
].retry
= backoff(radius
[r
].try++);
1693 if (radius
[r
].try > 5)
1695 sessionshutdown(s
, "CHAP timeout.", 3, 0);
1696 STAT(tunnel_tx_errors
);
1699 q
= makeppp(b
, sizeof(b
), 0, 0, s
, t
, PPPCHAP
);
1702 *q
= 1; // challenge
1703 q
[1] = radius
[r
].id
; // ID
1704 q
[4] = 16; // value size (size of challenge)
1705 memcpy(q
+ 5, radius
[r
].auth
, 16); // challenge
1706 strcpy((char *) q
+ 21, hostname
); // our name
1707 *(uint16_t *) (q
+ 2) = htons(strlen(hostname
) + 21); // length
1708 tunnelsend(b
, strlen(hostname
) + 21 + (q
- b
), t
); // send it
1711 // fill in a L2TP message with a PPP frame,
1712 // copies existing PPP message and changes magic number if seen
1713 // returns start of PPP frame
1714 uint8_t *makeppp(uint8_t *b
, int size
, uint8_t *p
, int l
, sessionidt s
, tunnelidt t
, uint16_t mtype
)
1716 if (size
< 12) // Need more space than this!!
1718 static int backtrace_count
= 0;
1719 LOG(0, s
, t
, "makeppp buffer too small for L2TP header (size=%d)\n", size
);
1720 log_backtrace(backtrace_count
, 5)
1724 *(uint16_t *) (b
+ 0) = htons(0x0002); // L2TP with no options
1725 *(uint16_t *) (b
+ 2) = htons(tunnel
[t
].far
); // tunnel
1726 *(uint16_t *) (b
+ 4) = htons(session
[s
].far
); // session
1728 if (mtype
== PPPLCP
|| !(session
[s
].l2tp_flags
& SESSIONACFC
))
1730 *(uint16_t *) b
= htons(0xFF03); // HDLC header
1733 if (mtype
< 0x100 && session
[s
].l2tp_flags
& SESSIONPFC
)
1737 *(uint16_t *) b
= htons(mtype
);
1743 static int backtrace_count
= 0;
1744 LOG(2, s
, t
, "makeppp would overflow buffer (size=%d, header+payload=%d)\n", size
, l
+ 12);
1745 log_backtrace(backtrace_count
, 5)
1755 static int add_lcp_auth(uint8_t *b
, int size
, int authtype
)
1758 if ((authtype
== AUTHCHAP
&& size
< 5) || size
< 4)
1761 *b
++ = 3; // Authentication-Protocol
1762 if (authtype
== AUTHCHAP
)
1764 len
= *b
++ = 5; // length
1765 *(uint16_t *) b
= htons(PPPCHAP
); b
+= 2;
1768 else if (authtype
== AUTHPAP
)
1770 len
= *b
++ = 4; // length
1771 *(uint16_t *) b
= htons(PPPPAP
); b
+= 2;
1775 LOG(0, 0, 0, "add_lcp_auth called with unsupported auth type %d\n", authtype
);
1781 // Send initial LCP ConfigReq for MRU, authentication type and magic no
1782 void sendlcp(sessionidt s
, tunnelidt t
, int authtype
)
1784 uint8_t b
[500], *q
, *l
;
1786 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, s
, t
, PPPLCP
)))
1789 LOG(3, s
, t
, "LCP: send ConfigReq%s%s%s\n",
1790 authtype
? " (" : "",
1791 authtype
? (authtype
== AUTHCHAP
? "CHAP" : "PAP") : "",
1792 authtype
? ")" : "");
1794 if (!session
[s
].mru
)
1795 session
[s
].mru
= DEFAULT_MRU
;
1799 *l
++ = (time_now
% 255) + 1; // ID
1801 l
+= 2; //Save space for length
1803 *l
++ = 1; *l
++ = 4; // Maximum-Receive-Unit (length 4)
1804 *(uint16_t *) l
= htons(session
[s
].mru
); l
+= 2;
1807 l
+= add_lcp_auth(l
, sizeof(b
) - (l
- b
), authtype
);
1809 *l
++ = 5; *l
++ = 6; // Magic-Number (length 6)
1810 *(uint32_t *) l
= htonl(session
[s
].magic
);
1813 *(uint16_t *)(q
+ 2) = htons(l
- q
); // Length
1815 LOG_HEX(5, "PPPLCP", q
, l
- q
);
1816 if (config
->debug
> 3) dumplcp(q
, l
- q
);
1818 tunnelsend(b
, (l
- b
), t
);
1821 // Send CCP request for no compression
1822 void sendccp(sessionidt s
, tunnelidt t
)
1826 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, s
, t
, PPPCCP
)))
1829 LOG(4, s
, t
, "Sending CCP ConfigReq for no compression\n");
1831 *(uint8_t *)(q
+ 1) = (time_now
% 255) + 1; // ID
1832 *(uint16_t *)(q
+ 2) = htons(4); // Length
1834 LOG_HEX(5, "PPPCCP", q
, 4);
1835 tunnelsend(b
, (q
- b
) + 4 , t
);