3 char const *cvs_id_ppp
= "$Id: ppp.c,v 1.39.2.2 2005/02/14 05:55: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 void initccp(tunnelidt t
, sessionidt s
);
28 // Process PAP messages
29 void processpap(tunnelidt t
, sessionidt s
, uint8_t *p
, uint16_t l
)
35 CSTAT(call_processpap
);
37 LOG_HEX(5, "PAP", p
, l
);
40 LOG(1, s
, t
, "Short PAP %u bytes\n", l
);
41 STAT(tunnel_rx_errors
);
45 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
47 LOG(1, s
, t
, "Length mismatch PAP %u/%u\n", hl
, l
);
48 STAT(tunnel_rx_errors
);
55 LOG(1, s
, t
, "Unexpected PAP code %d\n", *p
);
56 STAT(tunnel_rx_errors
);
63 user
[0] = pass
[0] = 0;
64 if (*b
&& *b
< sizeof(user
))
66 memcpy(user
, b
+ 1, *b
);
69 if (*b
&& *b
< sizeof(pass
))
71 memcpy(pass
, b
+ 1, *b
);
75 LOG(3, s
, t
, "PAP login %s/%s\n", user
, pass
);
77 if (session
[s
].ip
|| !session
[s
].radius
)
79 // respond now, either no RADIUS available or already authenticated
80 uint8_t b
[MAXCONTROL
];
82 uint8_t *p
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPPAP
);
88 *p
= 3; // cant authorise
90 *(uint16_t *) (p
+ 2) = htons(5); // length
91 p
[4] = 0; // no message
94 LOG(3, s
, t
, "Already an IP allocated: %s (%d)\n",
95 fmtaddr(htonl(session
[s
].ip
), 0), session
[s
].ip_pool_index
);
97 session
[s
].flags
&= ~SF_IPCP_ACKED
;
101 LOG(1, s
, t
, "No radius session available to authenticate session...\n");
103 LOG(3, s
, t
, "Fallback response to PAP (%s)\n", (session
[s
].ip
) ? "ACK" : "NAK");
104 tunnelsend(b
, 5 + (p
- b
), t
); // send it
108 // set up RADIUS request
109 uint16_t r
= session
[s
].radius
;
111 // Run PRE_AUTH plugins
112 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], strdup(user
), strdup(pass
), PPPPAP
, 1 };
113 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
114 if (!packet
.continue_auth
)
116 LOG(3, s
, t
, "A plugin rejected PRE_AUTH\n");
117 if (packet
.username
) free(packet
.username
);
118 if (packet
.password
) free(packet
.password
);
122 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
123 strncpy(radius
[r
].pass
, packet
.password
, sizeof(radius
[r
].pass
) - 1);
125 free(packet
.username
);
126 free(packet
.password
);
129 LOG(3, s
, t
, "Sending login for %s/%s to radius\n", user
, pass
);
130 radiussend(r
, RADIUSAUTH
);
134 // Process CHAP messages
135 void processchap(tunnelidt t
, sessionidt s
, uint8_t *p
, uint16_t l
)
140 CSTAT(call_processchap
);
142 LOG_HEX(5, "CHAP", p
, l
);
143 r
= session
[s
].radius
;
146 LOG(1, s
, t
, "Unexpected CHAP message\n");
148 // FIXME: Need to drop the session here.
150 STAT(tunnel_rx_errors
);
156 LOG(1, s
, t
, "Short CHAP %u bytes\n", l
);
157 STAT(tunnel_rx_errors
);
161 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
163 LOG(1, s
, t
, "Length mismatch CHAP %u/%u\n", hl
, l
);
164 STAT(tunnel_rx_errors
);
171 LOG(1, s
, t
, "Unexpected CHAP response code %d\n", *p
);
172 STAT(tunnel_rx_errors
);
175 if (p
[1] != radius
[r
].id
)
177 LOG(1, s
, t
, "Wrong CHAP response ID %d (should be %d) (%d)\n", p
[1], radius
[r
].id
, r
);
178 STAT(tunnel_rx_errors
);
182 if (l
< 5 || p
[4] != 16)
184 LOG(1, s
, t
, "Bad CHAP response length %d\n", l
< 5 ? -1 : p
[4]);
185 STAT(tunnel_rx_errors
);
191 if (l
< 16 || l
- 16 >= sizeof(session
[s
].user
))
193 LOG(1, s
, t
, "CHAP user too long %d\n", l
- 16);
194 STAT(tunnel_rx_errors
);
198 // Run PRE_AUTH plugins
200 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], NULL
, NULL
, PPPCHAP
, 1 };
202 packet
.password
= calloc(17, 1);
203 memcpy(packet
.password
, p
, 16);
208 packet
.username
= calloc(l
+ 1, 1);
209 memcpy(packet
.username
, p
, l
);
211 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
212 if (!packet
.continue_auth
)
214 LOG(3, s
, t
, "A plugin rejected PRE_AUTH\n");
215 if (packet
.username
) free(packet
.username
);
216 if (packet
.password
) free(packet
.password
);
220 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
221 memcpy(radius
[r
].pass
, packet
.password
, 16);
223 free(packet
.username
);
224 free(packet
.password
);
228 LOG(3, s
, t
, "CHAP login %s\n", session
[s
].user
);
229 radiussend(r
, RADIUSAUTH
);
232 static char *ppp_lcp_types
[] = {
248 static void dumplcp(uint8_t *p
, int l
)
251 uint8_t *o
= (p
+ 4);
253 LOG_HEX(5, "PPP LCP Packet", p
, l
);
254 LOG(4, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p
, ppp_lcp_types
[(int)*p
], ntohs( ((uint16_t *) p
)[1]) );
255 LOG(4, 0, 0, "Length: %d\n", l
);
256 if (*p
!= ConfigReq
&& *p
!= ConfigRej
&& *p
!= ConfigAck
)
265 LOG(4, 0, 0, " Option length is %d...\n", length
);
270 LOG(4, 0, 0, " Option type is 0...\n");
277 case 1: // Maximum-Receive-Unit
279 LOG(4, 0, 0, " %s %d\n", lcp_types
[type
], ntohs(*(uint16_t *)(o
+ 2)));
281 LOG(4, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
283 case 2: // Async-Control-Character-Map
286 uint32_t asyncmap
= ntohl(*(uint32_t *)(o
+ 2));
287 LOG(4, 0, 0, " %s %x\n", lcp_types
[type
], asyncmap
);
290 LOG(4, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
292 case 3: // Authentication-Protocol
295 int proto
= ntohs(*(uint16_t *)(o
+ 2));
296 LOG(4, 0, 0, " %s 0x%x (%s)\n", lcp_types
[type
], proto
,
297 proto
== PPPCHAP
? "CHAP" :
298 proto
== PPPPAP
? "PAP" : "UNKNOWN");
301 LOG(4, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
303 case 4: // Quality-Protocol
305 uint32_t qp
= ntohl(*(uint32_t *)(o
+ 2));
306 LOG(4, 0, 0, " %s %x\n", lcp_types
[type
], qp
);
309 case 5: // Magic-Number
312 uint32_t magicno
= ntohl(*(uint32_t *)(o
+ 2));
313 LOG(4, 0, 0, " %s %x\n", lcp_types
[type
], magicno
);
316 LOG(4, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
318 case 7: // Protocol-Field-Compression
319 case 8: // Address-And-Control-Field-Compression
320 LOG(4, 0, 0, " %s\n", lcp_types
[type
]);
323 LOG(2, 0, 0, " Unknown PPP LCP Option type %d\n", type
);
331 // Process LCP messages
332 void processlcp(tunnelidt t
, sessionidt s
, uint8_t *p
, uint16_t l
)
334 uint8_t b
[MAXCONTROL
];
336 uint32_t magicno
= 0;
339 CSTAT(call_processlcp
);
341 LOG_HEX(5, "LCP", p
, l
);
344 LOG(1, s
, t
, "Short LCP %d bytes\n", l
);
345 STAT(tunnel_rx_errors
);
349 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
351 LOG(1, s
, t
, "Length mismatch LCP %u/%u\n", hl
, l
);
352 STAT(tunnel_rx_errors
);
359 LOG(3, s
, t
, "LCP: Discarding ConfigAck\n");
360 session
[s
].flags
|= SF_LCP_ACKED
;
362 else if (*p
== ConfigReq
)
365 uint8_t *o
= (p
+ 4);
366 uint8_t *response
= 0;
368 LOG(3, s
, t
, "LCP: ConfigReq (%d bytes)...\n", l
);
369 if (config
->debug
> 3) dumplcp(p
, l
);
376 if (length
== 0 || type
== 0 || x
< length
) break;
379 case 1: // Maximum-Receive-Unit
380 session
[s
].mru
= ntohs(*(uint16_t *)(o
+ 2));
383 case 2: // Async-Control-Character-Map
384 if (!ntohl(*(uint32_t *)(o
+ 2))) // all bits zero is OK
387 if (response
&& *response
!= ConfigNak
) // rej already queued
390 LOG(2, s
, t
, " Remote requesting asyncmap. Rejecting.\n");
393 q
= response
= makeppp(b
, sizeof(b
), p
, 2, t
, s
, PPPLCP
);
399 if ((q
- b
+ 11) > sizeof(b
))
401 LOG(2, s
, t
, "LCP overflow for asyncmap ConfigNak.\n");
407 memset(q
, 0, 4); // asyncmap 0
409 *((uint16_t *) (response
+ 2)) = htons(q
- response
); // LCP header length
412 case 3: // Authentication-Protocol
414 int proto
= ntohs(*(uint16_t *)(o
+ 2));
415 char proto_name
[] = "0x0000";
419 if (response
&& *response
!= ConfigNak
) // rej already queued
422 if (proto
== PPPCHAP
)
423 strcpy(proto_name
, "CHAP");
425 sprintf(proto_name
, "%#4.4x", proto
);
427 LOG(2, s
, t
, " Remote requesting %s authentication. Rejecting.\n", proto_name
);
431 q
= response
= makeppp(b
, sizeof(b
), p
, 2, t
, s
, PPPLCP
);
437 if ((q
- b
+ length
) > sizeof(b
))
439 LOG(2, s
, t
, "LCP overflow for %s ConfigNak.\n", proto_name
);
443 memcpy(q
, o
, length
);
444 *(uint16_t *)(q
+= 2) = htons(PPPPAP
); // NAK -> Use PAP instead
446 *((uint16_t *) (response
+ 2)) = htons(q
- response
);
450 case 5: // Magic-Number
451 magicno
= ntohl(*(uint32_t *)(o
+ 2));
454 case 4: // Quality-Protocol
455 case 7: // Protocol-Field-Compression
456 case 8: // Address-And-Control-Field-Compression
459 default: // Reject any unknown options
460 LOG(2, s
, t
, " Rejecting PPP LCP Option type %d\n", type
);
461 if (!response
|| *response
!= ConfigRej
) // drop nak in favour of rej
463 q
= response
= makeppp(b
, sizeof(b
), p
, 2, t
, s
, PPPLCP
);
469 if ((q
- b
+ length
) > sizeof(b
))
471 LOG(2, s
, t
, "LCP overflow for ConfigRej (type=%d).\n", type
);
475 memcpy(q
, o
, length
);
477 *((uint16_t *) (response
+ 2)) = htons(q
- response
); // LCP header length
485 // Send back a ConfigAck
486 q
= response
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
491 LOG(3, s
, t
, "Sending %s\n", ppp_lcp_types
[*response
]);
492 tunnelsend(b
, l
+ (q
- b
), t
);
494 if (!(session
[s
].flags
& SF_LCP_ACKED
))
497 else if (*p
== ConfigNak
)
499 LOG(1, s
, t
, "Remote end sent a ConfigNak. Ignoring\n");
500 if (config
->debug
> 3) dumplcp(p
, l
);
503 else if (*p
== TerminateReq
)
505 LOG(3, s
, t
, "LCP: Received TerminateReq. Sending TerminateAck\n");
506 *p
= TerminateAck
; // close
507 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
509 tunnelsend(b
, l
+ (q
- b
), t
); // send it
510 sessionshutdown(s
, "Remote end closed connection.");
512 else if (*p
== TerminateAck
)
514 sessionshutdown(s
, "Connection closed.");
516 else if (*p
== EchoReq
)
518 LOG(5, s
, t
, "LCP: Received EchoReq. Sending EchoReply\n");
519 *p
= EchoReply
; // reply
520 *(uint32_t *) (p
+ 4) = htonl(session
[s
].magic
); // our magic number
521 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
523 tunnelsend(b
, l
+ (q
- b
), t
); // send it
525 else if (*p
== EchoReply
)
527 // Ignore it, last_packet time is set earlier than this.
529 else if (*p
== IdentRequest
)
534 LOG(1, s
, t
, "Truncated Ident Packet (length=%d) to 1400 bytes\n", l
);
537 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
539 LOG_HEX(5, "LCPIdentRej", q
, l
+ 4);
540 tunnelsend(b
, 12 + 4 + l
, t
);
544 LOG(1, s
, t
, "Unexpected LCP code %d\n", *p
);
545 STAT(tunnel_rx_errors
);
550 // find a PPP option, returns point to option, or 0 if not found
551 static uint8_t *findppp(uint8_t *b
, uint8_t mtype
)
553 uint16_t l
= ntohs(*(uint16_t *) (b
+ 2));
560 if (l
< b
[1] || !b
[1])
570 // Process IPCP messages
571 void processipcp(tunnelidt t
, sessionidt s
, uint8_t *p
, uint16_t l
)
575 CSTAT(call_processipcp
);
577 LOG_HEX(5, "IPCP", p
, l
);
580 LOG(1, s
, t
, "Short IPCP %d bytes\n", l
);
581 STAT(tunnel_rx_errors
);
585 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
587 LOG(1, s
, t
, "Length mismatch IPCP %u/%u\n", hl
, l
);
588 STAT(tunnel_rx_errors
);
595 // happy with our IPCP
596 uint16_t r
= session
[s
].radius
;
597 if ((!r
|| radius
[r
].state
== RADIUSIPCP
) && !session
[s
].walled_garden
)
602 radiussend(r
, RADIUSSTART
); // send radius start, having got IPCP at last
604 session
[s
].flags
|= SF_IPCP_ACKED
;
606 LOG(3, s
, t
, "IPCP Acked, session is now active\n");
608 // clear LCP_ACKED/CCP_ACKED flag for possible fast renegotiaion for routers
609 session
[s
].flags
&= ~(SF_LCP_ACKED
|SF_CCP_ACKED
);
615 LOG(1, s
, t
, "Unexpected IPCP code %d\n", *p
);
616 STAT(tunnel_rx_errors
);
619 LOG(4, s
, t
, "IPCP ConfigReq received\n");
623 LOG(3, s
, t
, "Waiting on radius reply\n");
624 return; // have to wait on RADIUS reply
626 // form a config reply quoting the IP in the session
628 uint8_t b
[MAXCONTROL
];
633 while (q
< i
&& q
[1])
635 if (*q
!= 0x81 && *q
!= 0x83 && *q
!= 3)
644 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
649 while (p
< i
&& p
[1])
651 if (*p
!= 0x81 && *p
!= 0x83 && *p
!= 3)
653 LOG(2, s
, t
, "IPCP reject %d\n", *p
);
654 memcpy(q
+ n
, p
, p
[1]);
659 *(uint16_t *) (q
+ 2) = htons(n
);
660 LOG(4, s
, t
, "Sending ConfigRej\n");
661 tunnelsend(b
, n
+ (q
- b
), t
); // send it
665 LOG(4, s
, t
, "Sending ConfigAck\n");
667 if ((i
= findppp(p
, 0x81))) // Primary DNS address
669 if (*(uint32_t *) (i
+ 2) != htonl(session
[s
].dns1
))
671 *(uint32_t *) (i
+ 2) = htonl(session
[s
].dns1
);
673 LOG(5, s
, t
, " DNS1 = %s\n",
674 fmtaddr(htonl(session
[s
].dns1
), 0));
677 if ((i
= findppp(p
, 0x83))) // Secondary DNS address (TBA, is it)
679 if (*(uint32_t *) (i
+ 2) != htonl(session
[s
].dns2
))
681 *(uint32_t *) (i
+ 2) = htonl(session
[s
].dns2
);
683 LOG(5, s
, t
, " DNS2 = %s\n",
684 fmtaddr(htonl(session
[s
].dns2
), 0));
687 i
= findppp(p
, 3); // IP address
690 LOG(1, s
, t
, "No IP in IPCP request\n");
691 STAT(tunnel_rx_errors
);
694 if (*(uint32_t *) (i
+ 2) != htonl(session
[s
].ip
))
696 *(uint32_t *) (i
+ 2) = htonl(session
[s
].ip
);
698 LOG(4, s
, t
, " No, a ConfigNak, client is requesting IP - sending %s\n",
699 fmtaddr(htonl(session
[s
].ip
), 0));
701 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
704 tunnelsend(b
, l
+ (q
- b
), t
); // send it
709 // process IP packet received
711 // This MUST be called with at least 4 byte behind 'p'.
712 // (i.e. this routine writes to p[-4]).
713 void processipin(tunnelidt t
, sessionidt s
, uint8_t *p
, uint16_t l
)
717 CSTAT(call_processipin
);
719 LOG_HEX(5, "IP", p
, l
);
721 ip
= ntohl(*(uint32_t *)(p
+ 12));
725 LOG(1, s
, t
, "IP packet too long %d\n", l
);
726 STAT(tunnel_rx_errors
);
730 // no spoof (do sessionbyip to handled statically routed subnets)
731 if (ip
!= session
[s
].ip
&& sessionbyip(htonl(ip
)) != s
)
733 LOG(5, s
, t
, "Dropping packet with spoofed IP %s\n", fmtaddr(htonl(ip
), 0));
737 // run access-list if any
738 if (session
[s
].filter_in
&& !ip_filter(p
, l
, session
[s
].filter_in
- 1))
741 // Add on the tun header
743 *(uint32_t *) p
= htonl(0x00000800);
746 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) { // Are we throttled and a slave?
747 master_throttle_packet(session
[s
].tbf_in
, p
, l
); // Pass it to the master for handling.
751 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) { // Are we throttled and a master?? actually handle the throttled packets.
752 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
757 if (tun_write(p
, l
) < 0)
760 LOG(0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
761 l
, strerror(errno
), tunfd
, p
);
766 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
768 // Snooping this session
769 snoop_send_packet(p
+ 4, l
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
772 session
[s
].cin
+= l
- 4;
773 session
[s
].total_cin
+= l
- 4;
774 sess_local
[s
].cin
+= l
- 4;
779 STAT(tun_tx_packets
);
780 INC_STAT(tun_tx_bytes
, l
- 4);
784 // Helper routine for the TBF filters.
785 // Used to send queued data in from the user.
787 void send_ipin(sessionidt s
, uint8_t *buf
, int len
)
789 LOG_HEX(5, "IP in throttled", buf
, len
);
791 if (write(tunfd
, buf
, len
) < 0)
794 LOG(0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
795 len
, strerror(errno
), tunfd
, buf
);
800 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
802 // Snooping this session
803 snoop_send_packet(buf
+ 4, len
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
806 // Increment packet counters
807 session
[s
].cin
+= len
- 4;
808 session
[s
].total_cin
+= len
- 4;
809 sess_local
[s
].cin
+= len
- 4;
814 STAT(tun_tx_packets
);
815 INC_STAT(tun_tx_bytes
, len
- 4);
819 // Process CCP messages
820 void processccp(tunnelidt t
, sessionidt s
, uint8_t *p
, uint16_t l
)
822 uint8_t b
[MAXCONTROL
];
825 CSTAT(call_processccp
);
827 LOG_HEX(5, "CCP", p
, l
);
828 switch (l
> 1 ? *p
: 0)
831 session
[s
].flags
|= SF_CCP_ACKED
;
835 if (l
< 6) // accept no compression
841 // compression requested--reject
844 // send CCP request for no compression for our end if not negotiated
845 if (!(session
[s
].flags
& SF_CCP_ACKED
))
856 LOG(1, s
, t
, "Unexpected CCP request code %d\n", *p
);
858 LOG(1, s
, t
, "Short CCP packet\n");
860 STAT(tunnel_rx_errors
);
864 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPCCP
)))
867 tunnelsend(b
, l
+ (q
- b
), t
); // send it
870 // send a CHAP PP packet
871 void sendchap(tunnelidt t
, sessionidt s
)
873 uint8_t b
[MAXCONTROL
];
874 uint16_t r
= session
[s
].radius
;
877 CSTAT(call_sendchap
);
881 LOG(1, s
, t
, "No RADIUS to send challenge\n");
882 STAT(tunnel_tx_errors
);
885 LOG(1, s
, t
, "Send CHAP challenge\n");
889 for (n
= 0; n
< 15; n
++)
890 radius
[r
].auth
[n
] = rand();
892 radius
[r
].chap
= 1; // CHAP not PAP
894 if (radius
[r
].state
!= RADIUSCHAP
)
896 radius
[r
].state
= RADIUSCHAP
;
897 radius
[r
].retry
= backoff(radius
[r
].try++);
898 if (radius
[r
].try > 5)
900 sessionshutdown(s
, "Timeout CHAP");
901 STAT(tunnel_tx_errors
);
904 q
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPCHAP
);
908 q
[1] = radius
[r
].id
; // ID
910 memcpy(q
+ 5, radius
[r
].auth
, 16); // challenge
911 strcpy(q
+ 21, hostname
); // our name
912 *(uint16_t *) (q
+ 2) = htons(strlen(hostname
) + 21); // length
913 tunnelsend(b
, strlen(hostname
) + 21 + (q
- b
), t
); // send it
916 // fill in a L2TP message with a PPP frame,
917 // copies existing PPP message and changes magic number if seen
918 // returns start of PPP frame
919 uint8_t *makeppp(uint8_t *b
, int size
, uint8_t *p
, int l
, tunnelidt t
, sessionidt s
, uint16_t mtype
)
921 if (size
< 12) // Need more space than this!!
923 static int backtrace_count
= 0;
924 LOG(0, s
, t
, "makeppp buffer too small for L2TP header (size=%d)\n", size
);
925 log_backtrace(backtrace_count
, 5)
929 *(uint16_t *) (b
+ 0) = htons(0x0002); // L2TP with no options
930 *(uint16_t *) (b
+ 2) = htons(tunnel
[t
].far
); // tunnel
931 *(uint16_t *) (b
+ 4) = htons(session
[s
].far
); // session
933 if (mtype
== PPPLCP
|| !(session
[s
].l2tp_flags
& SESSIONACFC
))
935 *(uint16_t *) b
= htons(0xFF03); // HDLC header
938 if (mtype
< 0x100 && session
[s
].l2tp_flags
& SESSIONPFC
)
942 *(uint16_t *) b
= htons(mtype
);
948 static int backtrace_count
= 0;
949 LOG(2, s
, t
, "makeppp would overflow buffer (size=%d, header+payload=%d)\n", size
, l
+ 12);
950 log_backtrace(backtrace_count
, 5)
960 // Send initial LCP ConfigReq for PAP, set magic no.
961 void initlcp(tunnelidt t
, sessionidt s
)
965 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
)))
968 LOG(4, s
, t
, "Sending LCP ConfigReq for PAP\n");
970 *(uint8_t *)(q
+ 1) = (time_now
% 255) + 1; // ID
971 *(uint16_t *)(q
+ 2) = htons(14); // Length
972 *(uint8_t *)(q
+ 4) = 5;
973 *(uint8_t *)(q
+ 5) = 6;
974 *(uint32_t *)(q
+ 6) = htonl(session
[s
].magic
);
975 *(uint8_t *)(q
+ 10) = 3;
976 *(uint8_t *)(q
+ 11) = 4;
977 *(uint16_t *)(q
+ 12) = htons(PPPPAP
); // PAP
979 LOG_HEX(5, "PPPLCP", q
, 14);
980 tunnelsend(b
, (q
- b
) + 14, t
);
983 // Send CCP request for no compression
984 static void initccp(tunnelidt t
, sessionidt s
)
988 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPCCP
)))
991 LOG(4, s
, t
, "Sending CCP ConfigReq for no compression\n");
993 *(uint8_t *)(q
+ 1) = (time_now
% 255) + 1; // ID
994 *(uint16_t *)(q
+ 2) = htons(4); // Length
996 LOG_HEX(5, "PPPCCP", q
, 4);
997 tunnelsend(b
, (q
- b
) + 4 , t
);