2ca71f91c20ddf201b5bbaeaf12bd7c409ea9647
3 char const *cvs_id_ppp
= "$Id: ppp.c,v 1.21 2004/11/05 04:55:27 bodea Exp $";
11 #include "constants.h"
17 extern tunnelt
*tunnel
;
18 extern sessiont
*session
;
19 extern radiust
*radius
;
21 extern char hostname
[];
23 extern time_t time_now
;
24 extern struct configt
*config
;
26 void sendccp(tunnelidt t
, sessionidt s
);
28 // Process PAP messages
29 void processpap(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
35 CSTAT(call_processpap
);
37 LOG_HEX(5, "PAP", p
, l
);
40 LOG(1, 0, s
, t
, "Short PAP %u bytes\n", l
);
41 STAT(tunnel_rx_errors
);
45 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
47 LOG(1, 0, s
, t
, "Length mismatch PAP %u/%u\n", hl
, l
);
48 STAT(tunnel_rx_errors
);
55 LOG(1, 0, s
, t
, "Unexpected PAP code %d\n", *p
);
56 STAT(tunnel_rx_errors
);
63 if (*b
&& *b
< sizeof(user
))
64 memcpy(user
, b
+ 1, *b
);
67 if (*b
&& *b
< sizeof(pass
))
68 memcpy(pass
, b
+ 1, *b
);
70 LOG(3, 0, s
, t
, "PAP login %s/%s\n", user
, pass
);
72 if (session
[s
].ip
|| !session
[s
].radius
)
74 // respond now, either no RADIUS available or already authenticated
77 u8
*p
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPPAP
);
78 if (!p
) { // Failed to make ppp header!
79 LOG(1,0,0,0, "Failed to make PPP header in process pap!\n");
85 *p
= 3; // cant authorise
87 *(u16
*) (p
+ 2) = htons(5); // length
88 p
[4] = 0; // no message
91 LOG(3, session
[s
].ip
, s
, t
, "Already an IP allocated: %s (%d)\n", inet_toa(htonl(session
[s
].ip
)), session
[s
].ip_pool_index
);
92 session
[s
].flags
&= ~SF_IPCP_ACKED
;
96 LOG(1, 0, s
, t
, "No radius session available to authenticate session...\n");
98 LOG(3, 0, s
, t
, "Fallback response to PAP (%s)\n", (session
[s
].ip
) ? "ACK" : "NAK");
99 tunnelsend(b
, 5 + (p
- b
), t
); // send it
103 // set up RADIUS request
104 u16 r
= session
[s
].radius
;
106 // Run PRE_AUTH plugins
107 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], strdup(user
), strdup(pass
), PPPPAP
, 1 };
108 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
109 if (!packet
.continue_auth
)
111 LOG(3, 0, s
, t
, "A plugin rejected PRE_AUTH\n");
112 if (packet
.username
) free(packet
.username
);
113 if (packet
.password
) free(packet
.password
);
117 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
118 strncpy(radius
[r
].pass
, packet
.password
, sizeof(radius
[r
].pass
) - 1);
120 free(packet
.username
);
121 free(packet
.password
);
124 LOG(3, 0, s
, t
, "Sending login for %s/%s to radius\n", user
, pass
);
125 radiussend(r
, RADIUSAUTH
);
129 // Process CHAP messages
130 void processchap(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
135 CSTAT(call_processchap
);
137 LOG_HEX(5, "CHAP", p
, l
);
138 r
= session
[s
].radius
;
141 LOG(1, 0, s
, t
, "Unexpected CHAP message\n");
143 // FIXME: Need to drop the session here.
145 STAT(tunnel_rx_errors
);
151 LOG(1, 0, s
, t
, "Short CHAP %u bytes\n", l
);
152 STAT(tunnel_rx_errors
);
156 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
158 LOG(1, 0, s
, t
, "Length mismatch CHAP %u/%u\n", hl
, l
);
159 STAT(tunnel_rx_errors
);
166 LOG(1, 0, s
, t
, "Unexpected CHAP response code %d\n", *p
);
167 STAT(tunnel_rx_errors
);
170 if (p
[1] != radius
[r
].id
)
172 LOG(1, 0, s
, t
, "Wrong CHAP response ID %d (should be %d) (%d)\n", p
[1], radius
[r
].id
, r
);
173 STAT(tunnel_rx_errors
);
177 if (l
< 5 || p
[4] != 16)
179 LOG(1, 0, s
, t
, "Bad CHAP response length %d\n", l
< 5 ? -1 : p
[4]);
180 STAT(tunnel_rx_errors
);
186 if (l
< 16 || l
- 16 >= sizeof(session
[s
].user
))
188 LOG(1, 0, s
, t
, "CHAP user too long %d\n", l
- 16);
189 STAT(tunnel_rx_errors
);
193 // Run PRE_AUTH plugins
195 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], NULL
, NULL
, PPPCHAP
, 1 };
197 packet
.password
= calloc(17, 1);
198 memcpy(packet
.password
, p
, 16);
203 packet
.username
= calloc(l
+ 1, 1);
204 memcpy(packet
.username
, p
, l
);
206 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
207 if (!packet
.continue_auth
)
209 LOG(3, 0, s
, t
, "A plugin rejected PRE_AUTH\n");
210 if (packet
.username
) free(packet
.username
);
211 if (packet
.password
) free(packet
.password
);
215 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
216 memcpy(radius
[r
].pass
, packet
.password
, 16);
218 free(packet
.username
);
219 free(packet
.password
);
223 LOG(3, 0, s
, t
, "CHAP login %s\n", session
[s
].user
);
224 radiussend(r
, RADIUSAUTH
);
227 char *ppp_lcp_types
[] = {
243 void dumplcp(u8
*p
, int l
)
248 LOG_HEX(5, "PPP LCP Packet", p
, l
);
249 LOG(4, 0, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p
, ppp_lcp_types
[(int)*p
], ntohs( ((u16
*) p
)[1]) );
250 LOG(4, 0, 0, 0, "Length: %d\n", l
);
251 if (*p
!= ConfigReq
&& *p
!= ConfigRej
&& *p
!= ConfigAck
)
260 LOG(4, 0, 0, 0, " Option length is %d...\n", length
);
265 LOG(4, 0, 0, 0, " Option type is 0...\n");
272 case 1: // Maximum-Receive-Unit
274 LOG(4, 0, 0, 0, " %s %d\n", lcp_types
[type
], ntohs(*(u16
*)(o
+ 2)));
276 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
278 case 3: // Authentication-Protocol
282 int proto
= ntohs(*(u16
*)(o
+ 2));
283 LOG(4, 0, 0, 0, " %s 0x%x (%s)\n", lcp_types
[type
], proto
,
284 proto
== PPPCHAP
? "CHAP" :
285 proto
== PPPPAP
? "PAP" : "UNKNOWN");
288 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
291 case 4: // Quality-Protocol
293 u32 qp
= ntohl(*(u32
*)(o
+ 2));
294 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], qp
);
297 case 5: // Magic-Number
301 u32 magicno
= ntohl(*(u32
*)(o
+ 2));
302 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], magicno
);
305 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
308 case 7: // Protocol-Field-Compression
310 LOG(4, 0, 0, 0, " %s\n", lcp_types
[type
]);
313 case 8: // Address-And-Control-Field-Compression
315 LOG(4, 0, 0, 0, " %s\n", lcp_types
[type
]);
319 LOG(2, 0, 0, 0, " Unknown PPP LCP Option type %d\n", type
);
327 // Process LCP messages
328 void processlcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
335 CSTAT(call_processlcp
);
337 LOG_HEX(5, "LCP", p
, l
);
340 LOG(1, session
[s
].ip
, s
, t
, "Short LCP %d bytes\n", l
);
341 STAT(tunnel_rx_errors
);
345 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
347 LOG(1, 0, s
, t
, "Length mismatch LCP %u/%u\n", hl
, l
);
348 STAT(tunnel_rx_errors
);
355 LOG(3, session
[s
].ip
, s
, t
, "LCP: Discarding ConfigAck\n");
356 session
[s
].flags
|= SF_LCP_ACKED
;
358 else if (*p
== ConfigReq
)
363 LOG(3, session
[s
].ip
, s
, t
, "LCP: ConfigReq (%d bytes)...\n", l
);
364 if (config
->debug
> 3) dumplcp(p
, l
);
370 if (length
== 0 || type
== 0) break;
373 case 1: // Maximum-Receive-Unit
374 session
[s
].mru
= ntohs(*(u16
*)(o
+ 2));
377 LOG_HEX(2, "PPP LCP Packet", p
, l
);
378 LOG(2, 0, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p
, ppp_lcp_types
[(int)*p
], ntohs( ((u16
*) p
)[1]) );
380 case 3: // Authentication-Protocol
382 int proto
= ntohs(*(u16
*)(o
+ 2));
383 if (proto
== PPPCHAP
)
385 LOG(2, session
[s
].ip
, s
, t
, " Remote end is trying to do CHAP. Rejecting it.\n");
389 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
391 LOG(2, session
[s
].ip
, s
, t
, " Failed to send packet.\n");
396 memcpy(q
, o
, length
);
397 *(u16
*)(q
+= 2) = htons(PPPPAP
); // NAK -> Use PAP instead
402 case 5: // Magic-Number
404 magicno
= ntohl(*(u32
*)(o
+ 2));
407 case 4: // Quality-Protocol
408 case 7: // Protocol-Field-Compression
409 case 8: // Address-And-Control-Field-Compression
411 case 13: // CallBack option for LCP extention of win2000/routers L2TP client
415 // Reject LCP CallBack
416 LOG(2, session
[s
].ip
, s
, t
, " PPP LCP Option type %d, len=%d\n", type
, length
);
417 memcpy(p
+ 4, o
, length
);
418 *(u16
*)(p
+ 2) = htons(length
+ 4);
420 q
= makeppp(b
,sizeof(b
), p
, length
+ 4, t
, s
, PPPLCP
);
421 tunnelsend(b
, 12 + length
+ 4, t
);
426 // Reject Unknown LCP Option to stop to send it again
427 LOG(2, session
[s
].ip
, s
, t
, " Unknown PPP LCP Option type %d\n", type
);
428 memcpy(p
+ 4, o
, length
);
429 *(u16
*)(p
+ 2) = htons(length
+ 4);
431 q
= makeppp(b
,sizeof(b
), p
, length
+ 4, t
, s
, PPPLCP
);
432 tunnelsend(b
, 12 + length
+ 4, t
);
439 if (!(session
[s
].flags
& SF_LCP_ACKED
))
444 // Send back a ConfigAck
445 LOG(3, session
[s
].ip
, s
, t
, "ConfigReq accepted, sending as Ack\n");
446 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
449 LOG(3, session
[s
].ip
, s
, t
, " failed to create packet.\n");
453 tunnelsend(b
, l
+ (q
- b
), t
);
457 // Already built a ConfigNak... send it
458 LOG(3, session
[s
].ip
, s
, t
, "Sending ConfigNak\n");
459 tunnelsend(b
, l
+ (q
- b
), t
);
462 else if (*p
== ConfigNak
)
464 LOG(1, session
[s
].ip
, s
, t
, "Remote end sent a ConfigNak. Ignoring\n");
465 if (config
->debug
> 3) dumplcp(p
, l
);
468 else if (*p
== TerminateReq
)
470 *p
= TerminateAck
; // close
471 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
473 LOG(3, session
[s
].ip
, s
, t
, "Failed to create PPP packet in processlcp.\n");
476 LOG(3, session
[s
].ip
, s
, t
, "LCP: Received TerminateReq. Sending TerminateAck\n");
477 sessionshutdown(s
, "Remote end closed connection.");
478 tunnelsend(b
, l
+ (q
- b
), t
); // send it
480 else if (*p
== TerminateAck
)
482 sessionshutdown(s
, "Connection closed.");
484 else if (*p
== EchoReq
)
486 *p
= EchoReply
; // reply
487 *(u32
*) (p
+ 4) = htonl(session
[s
].magic
); // our magic number
488 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
490 LOG(3, session
[s
].ip
, s
, t
, " failed to send EchoReply.\n");
493 LOG(5, session
[s
].ip
, s
, t
, "LCP: Received EchoReq. Sending EchoReply\n");
494 tunnelsend(b
, l
+ (q
- b
), t
); // send it
496 else if (*p
== EchoReply
)
498 // Ignore it, last_packet time is set earlier than this.
500 else if (*p
== IdentRequest
)
505 LOG(1, 0, s
, t
, "Truncated Ident Packet (length=%d) to 1400 bytes\n", l
);
508 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
511 LOG(3, session
[s
].ip
, s
, t
, "Failed to create IdentRej.\n");
514 LOG_HEX(5, "LCPIdentRej", q
, l
+ 4);
515 tunnelsend(b
, 12 + 4 + l
, t
);
519 LOG(1, session
[s
].ip
, s
, t
, "Unexpected LCP code %d\n", *p
);
520 STAT(tunnel_rx_errors
);
525 // Process IPCP messages
526 void processipcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
530 CSTAT(call_processipcp
);
532 LOG_HEX(5, "IPCP", p
, l
);
535 LOG(1, 0, s
, t
, "Short IPCP %d bytes\n", l
);
536 STAT(tunnel_rx_errors
);
540 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
542 LOG(1, 0, s
, t
, "Length mismatch IPCP %u/%u\n", hl
, l
);
543 STAT(tunnel_rx_errors
);
550 // happy with our IPCP
551 u16 r
= session
[s
].radius
;
552 if ((!r
|| radius
[r
].state
== RADIUSIPCP
) && !session
[s
].walled_garden
)
557 radiussend(r
, RADIUSSTART
); // send radius start, having got IPCP at last
559 session
[s
].flags
|= SF_IPCP_ACKED
;
561 LOG(3, session
[s
].ip
, s
, t
, "IPCP Acked, session is now active\n");
566 LOG(1, 0, s
, t
, "Unexpected IPCP code %d\n", *p
);
567 STAT(tunnel_rx_errors
);
570 LOG(4, session
[s
].ip
, s
, t
, "IPCP ConfigReq received\n");
574 LOG(3, 0, s
, t
, "Waiting on radius reply\n");
575 return; // have to wait on RADIUS reply
577 // form a config reply quoting the IP in the session
585 while (q
< i
&& q
[1])
587 if (*q
!= 0x81 && *q
!= 0x83 && *q
!= 3)
596 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
598 LOG(2, 0, s
, t
, "Failed to send IPCP ConfigRej\n");
603 while (p
< i
&& p
[1])
605 if (*p
!= 0x81 && *p
!= 0x83 && *p
!= 3)
607 LOG(2, 0, s
, t
, "IPCP reject %d\n", *p
);
608 memcpy(q
+ n
, p
, p
[1]);
613 *(u16
*) (q
+ 2) = htons(n
);
614 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigRej\n");
615 tunnelsend(b
, n
+ (q
- b
), t
); // send it
619 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigAck\n");
621 if ((i
= findppp(p
, 0x81))) // Primary DNS address
623 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns1
))
625 *(u32
*) (i
+ 2) = htonl(session
[s
].dns1
);
627 LOG(5, session
[s
].ip
, s
, t
, " DNS1 = %s\n", inet_toa(session
[s
].dns1
));
630 if ((i
= findppp(p
, 0x83))) // Secondary DNS address (TBA, is it)
632 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns2
))
634 *(u32
*) (i
+ 2) = htonl(session
[s
].dns2
);
636 LOG(5, session
[s
].ip
, s
, t
, " DNS2 = %s\n", inet_toa(session
[s
].dns2
));
639 i
= findppp(p
, 3); // IP address
642 LOG(1, 0, s
, t
, "No IP in IPCP request\n");
643 STAT(tunnel_rx_errors
);
646 if (*(u32
*) (i
+ 2) != htonl(session
[s
].ip
))
648 *(u32
*) (i
+ 2) = htonl(session
[s
].ip
);
650 LOG(4, session
[s
].ip
, s
, t
, " No, a ConfigNak, client is requesting IP - sending %s\n",
651 inet_toa(htonl(session
[s
].ip
)));
653 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
655 LOG(2, 0, s
, t
, " Failed to send IPCP packet.\n");
658 tunnelsend(b
, l
+ (q
- b
), t
); // send it
663 // process IP packet received
665 // This MUST be called with at least 4 byte behind 'p'.
666 // (i.e. this routine writes to p[-4]).
667 void processipin(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
671 CSTAT(call_processipin
);
673 LOG_HEX(5, "IP", p
, l
);
675 ip
= ntohl(*(u32
*)(p
+ 12));
679 LOG(1, ip
, s
, t
, "IP packet too long %d\n", l
);
680 STAT(tunnel_rx_errors
);
684 // no spoof (do sessionbyip to handled statically routed subnets)
685 if (ip
!= session
[s
].ip
&& sessionbyip(htonl(ip
)) != s
)
687 LOG(5, ip
, s
, t
, "Dropping packet with spoofed IP %s\n", inet_toa(htonl(ip
)));
691 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
693 // Snooping this session
694 snoop_send_packet(p
, l
, session
[s
].snoop_ip
, session
[s
].snoop_port
);
697 // Add on the tun header
699 *(u32
*)p
= htonl(0x00000800);
702 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) { // Are we throttled and a slave?
703 master_throttle_packet(session
[s
].tbf_in
, p
, l
); // Pass it to the master for handling.
707 session
[s
].cin
+= l
- 4;
708 session
[s
].total_cin
+= l
- 4;
709 sess_count
[s
].cin
+= l
- 4;
714 STAT(tun_tx_packets
);
715 INC_STAT(tun_tx_bytes
, l
);
717 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) { // Are we throttled and a master?? actually handle the throttled packets.
718 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
723 if (tun_write(p
, l
) < 0)
726 LOG(0, 0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
727 l
, strerror(errno
), tunfd
, p
);
733 // Helper routine for the TBF filters.
734 // Used to send queued data in from the user.
736 void send_ipin(sessionidt s
, u8
*buf
, int len
)
738 LOG_HEX(5, "IP in throttled", buf
, len
);
739 if (write(tunfd
, buf
, len
) < 0)
742 LOG(0, 0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
743 len
, strerror(errno
), tunfd
, buf
);
746 // Increment packet counters
747 session
[s
].cin
+= len
- 4;
748 session
[s
].total_cin
+= len
- 4;
749 sess_count
[s
].cin
+= len
- 4;
756 // Process CCP messages
757 void processccp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
760 CSTAT(call_processccp
);
762 LOG_HEX(5, "CCP", p
, l
);
763 if (l
< 2 || (*p
!= ConfigReq
&& *p
!= TerminateReq
))
765 LOG(1, 0, s
, t
, "Unexpected CCP request code %d\n", *p
);
766 STAT(tunnel_rx_errors
);
777 *p
= ConfigAck
; // accept no compression
781 *p
= ConfigRej
; // reject
786 *p
= TerminateAck
; // close
787 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPCCP
)))
789 LOG(1,0,0,0, "Failed to send CCP packet.\n");
792 tunnelsend(b
, l
+ (q
- b
), t
); // send it
796 // send a CHAP PP packet
797 void sendchap(tunnelidt t
, sessionidt s
)
800 u16 r
= session
[s
].radius
;
803 CSTAT(call_sendchap
);
807 LOG(1, 0, s
, t
, "No RADIUS to send challenge\n");
808 STAT(tunnel_tx_errors
);
811 LOG(1, 0, s
, t
, "Send CHAP challenge\n");
815 for (n
= 0; n
< 15; n
++)
816 radius
[r
].auth
[n
] = rand();
818 radius
[r
].chap
= 1; // CHAP not PAP
820 if (radius
[r
].state
!= RADIUSCHAP
)
822 radius
[r
].state
= RADIUSCHAP
;
823 radius
[r
].retry
= backoff(radius
[r
].try++);
824 if (radius
[r
].try > 5)
826 sessionshutdown(s
, "Timeout CHAP");
827 STAT(tunnel_tx_errors
);
830 q
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPCHAP
);
832 LOG(1, 0, s
, t
, "failed to send CHAP challenge.\n");
836 q
[1] = radius
[r
].id
; // ID
838 memcpy(q
+ 5, radius
[r
].auth
, 16); // challenge
839 strcpy(q
+ 21, hostname
); // our name
840 *(u16
*) (q
+ 2) = htons(strlen(hostname
) + 21); // length
841 tunnelsend(b
, strlen(hostname
) + 21 + (q
- b
), t
); // send it
844 // fill in a L2TP message with a PPP frame,
845 // copies existing PPP message and changes magic number if seen
846 // returns start of PPP frame
847 u8
*makeppp(u8
*b
, int size
, u8
*p
, int l
, tunnelidt t
, sessionidt s
, u16 mtype
)
850 return NULL
; // Need more space than this!!
852 *(u16
*) (b
+ 0) = htons(0x0002); // L2TP with no options
853 *(u16
*) (b
+ 2) = htons(tunnel
[t
].far
); // tunnel
854 *(u16
*) (b
+ 4) = htons(session
[s
].far
); // session
856 if (mtype
== PPPLCP
|| !(session
[s
].l2tp_flags
& SESSIONACFC
))
858 *(u16
*) b
= htons(0xFF03); // HDLC header
861 if (mtype
< 0x100 && session
[s
].l2tp_flags
& SESSIONPFC
)
865 *(u16
*) b
= htons(mtype
);
870 LOG(3,0,0,0, "Would have overflowed the buffer in makeppp: size %d, len %d.\n", size
, l
);
871 return NULL
; // Run out of room to hold the packet!
878 // find a PPP option, returns point to option, or 0 if not found
879 u8
*findppp(u8
*b
, u8 mtype
)
881 u16 l
= ntohs(*(u16
*) (b
+ 2));
888 if (l
< b
[1] || !b
[1])
898 // Send initial LCP ConfigReq
899 void initlcp(tunnelidt t
, sessionidt s
)
901 char b
[500] = {0}, *q
;
903 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
905 LOG(1, 0, s
, t
, "Failed to send LCP ConfigReq.\n");
908 LOG(4, 0, s
, t
, "Sending LCP ConfigReq for PAP\n");
910 *(u8
*)(q
+ 1) = (time_now
% 255) + 1; // ID
911 *(u16
*)(q
+ 2) = htons(14); // Length
914 *(u32
*)(q
+ 6) = htonl(session
[s
].magic
);
917 *(u16
*)(q
+ 12) = htons(PPPPAP
); // PAP
918 tunnelsend(b
, 12 + 14, t
);
922 void sendccp(tunnelidt t
, sessionidt s
)
924 char *q
, b
[500] = {0};
926 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPCCP
);
928 *(u8
*)(q
+ 1) = (time_now
% 255) + 1; // ID
929 *(u16
*)(q
+ 2) = htons(4); // Length
930 LOG_HEX(5, "PPPCCP", q
, 4);
931 tunnelsend(b
, (q
- b
) + 4 , t
);