323c4bd1f8c87eafc03083796f743adec2d08f8f
3 char const *cvs_id_ppp
= "$Id: ppp.c,v 1.32 2004/11/28 20:10:04 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 configt
*config
;
26 static void initccp(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
);
83 *p
= 3; // cant authorise
85 *(u16
*) (p
+ 2) = htons(5); // length
86 p
[4] = 0; // no message
89 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
);
90 session
[s
].flags
&= ~SF_IPCP_ACKED
;
94 LOG(1, 0, s
, t
, "No radius session available to authenticate session...\n");
96 LOG(3, 0, s
, t
, "Fallback response to PAP (%s)\n", (session
[s
].ip
) ? "ACK" : "NAK");
97 tunnelsend(b
, 5 + (p
- b
), t
); // send it
101 // set up RADIUS request
102 u16 r
= session
[s
].radius
;
104 // Run PRE_AUTH plugins
105 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], strdup(user
), strdup(pass
), PPPPAP
, 1 };
106 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
107 if (!packet
.continue_auth
)
109 LOG(3, 0, s
, t
, "A plugin rejected PRE_AUTH\n");
110 if (packet
.username
) free(packet
.username
);
111 if (packet
.password
) free(packet
.password
);
115 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
116 strncpy(radius
[r
].pass
, packet
.password
, sizeof(radius
[r
].pass
) - 1);
118 free(packet
.username
);
119 free(packet
.password
);
122 LOG(3, 0, s
, t
, "Sending login for %s/%s to radius\n", user
, pass
);
123 radiussend(r
, RADIUSAUTH
);
127 // Process CHAP messages
128 void processchap(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
133 CSTAT(call_processchap
);
135 LOG_HEX(5, "CHAP", p
, l
);
136 r
= session
[s
].radius
;
139 LOG(1, 0, s
, t
, "Unexpected CHAP message\n");
141 // FIXME: Need to drop the session here.
143 STAT(tunnel_rx_errors
);
149 LOG(1, 0, s
, t
, "Short CHAP %u bytes\n", l
);
150 STAT(tunnel_rx_errors
);
154 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
156 LOG(1, 0, s
, t
, "Length mismatch CHAP %u/%u\n", hl
, l
);
157 STAT(tunnel_rx_errors
);
164 LOG(1, 0, s
, t
, "Unexpected CHAP response code %d\n", *p
);
165 STAT(tunnel_rx_errors
);
168 if (p
[1] != radius
[r
].id
)
170 LOG(1, 0, s
, t
, "Wrong CHAP response ID %d (should be %d) (%d)\n", p
[1], radius
[r
].id
, r
);
171 STAT(tunnel_rx_errors
);
175 if (l
< 5 || p
[4] != 16)
177 LOG(1, 0, s
, t
, "Bad CHAP response length %d\n", l
< 5 ? -1 : p
[4]);
178 STAT(tunnel_rx_errors
);
184 if (l
< 16 || l
- 16 >= sizeof(session
[s
].user
))
186 LOG(1, 0, s
, t
, "CHAP user too long %d\n", l
- 16);
187 STAT(tunnel_rx_errors
);
191 // Run PRE_AUTH plugins
193 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], NULL
, NULL
, PPPCHAP
, 1 };
195 packet
.password
= calloc(17, 1);
196 memcpy(packet
.password
, p
, 16);
201 packet
.username
= calloc(l
+ 1, 1);
202 memcpy(packet
.username
, p
, l
);
204 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
205 if (!packet
.continue_auth
)
207 LOG(3, 0, s
, t
, "A plugin rejected PRE_AUTH\n");
208 if (packet
.username
) free(packet
.username
);
209 if (packet
.password
) free(packet
.password
);
213 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
214 memcpy(radius
[r
].pass
, packet
.password
, 16);
216 free(packet
.username
);
217 free(packet
.password
);
221 LOG(3, 0, s
, t
, "CHAP login %s\n", session
[s
].user
);
222 radiussend(r
, RADIUSAUTH
);
225 static char *ppp_lcp_types
[] = {
241 static void dumplcp(u8
*p
, int l
)
246 LOG_HEX(5, "PPP LCP Packet", p
, l
);
247 LOG(4, 0, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p
, ppp_lcp_types
[(int)*p
], ntohs( ((u16
*) p
)[1]) );
248 LOG(4, 0, 0, 0, "Length: %d\n", l
);
249 if (*p
!= ConfigReq
&& *p
!= ConfigRej
&& *p
!= ConfigAck
)
258 LOG(4, 0, 0, 0, " Option length is %d...\n", length
);
263 LOG(4, 0, 0, 0, " Option type is 0...\n");
270 case 1: // Maximum-Receive-Unit
272 LOG(4, 0, 0, 0, " %s %d\n", lcp_types
[type
], ntohs(*(u16
*)(o
+ 2)));
274 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
276 case 2: // Async-Control-Character-Map
279 u32 asyncmap
= ntohl(*(u32
*)(o
+ 2));
280 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], asyncmap
);
283 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
285 case 3: // Authentication-Protocol
288 int proto
= ntohs(*(u16
*)(o
+ 2));
289 LOG(4, 0, 0, 0, " %s 0x%x (%s)\n", lcp_types
[type
], proto
,
290 proto
== PPPCHAP
? "CHAP" :
291 proto
== PPPPAP
? "PAP" : "UNKNOWN");
294 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
296 case 4: // Quality-Protocol
298 u32 qp
= ntohl(*(u32
*)(o
+ 2));
299 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], qp
);
302 case 5: // Magic-Number
305 u32 magicno
= ntohl(*(u32
*)(o
+ 2));
306 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], magicno
);
309 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
311 case 7: // Protocol-Field-Compression
312 case 8: // Address-And-Control-Field-Compression
313 LOG(4, 0, 0, 0, " %s\n", lcp_types
[type
]);
316 LOG(2, 0, 0, 0, " Unknown PPP LCP Option type %d\n", type
);
324 // Process LCP messages
325 void processlcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
332 CSTAT(call_processlcp
);
334 LOG_HEX(5, "LCP", p
, l
);
337 LOG(1, session
[s
].ip
, s
, t
, "Short LCP %d bytes\n", l
);
338 STAT(tunnel_rx_errors
);
342 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
344 LOG(1, 0, s
, t
, "Length mismatch LCP %u/%u\n", hl
, l
);
345 STAT(tunnel_rx_errors
);
352 LOG(3, session
[s
].ip
, s
, t
, "LCP: Discarding ConfigAck\n");
353 session
[s
].flags
|= SF_LCP_ACKED
;
355 else if (*p
== ConfigReq
)
361 LOG(3, session
[s
].ip
, s
, t
, "LCP: ConfigReq (%d bytes)...\n", l
);
362 if (config
->debug
> 3) dumplcp(p
, l
);
368 if (length
== 0 || type
== 0 || x
< length
) break;
371 case 1: // Maximum-Receive-Unit
372 session
[s
].mru
= ntohs(*(u16
*)(o
+ 2));
375 case 2: // Async-Control-Character-Map
376 if (!ntohl(*(u32
*)(o
+ 2))) // all bits zero is OK
379 if (response
&& response
!= ConfigNak
) // rej already queued
382 LOG(2, session
[s
].ip
, s
, t
, " Remote requesting asyncmap. Rejecting.\n");
385 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
387 response
= *q
++ = ConfigNak
;
390 if ((q
- b
+ 11) > sizeof(b
))
392 LOG(2, session
[s
].ip
, s
, t
, "LCP overflow for asyncmap ConfigNak.\n");
398 memset(q
, 0, 4); // asyncmap 0
402 case 3: // Authentication-Protocol
404 int proto
= ntohs(*(u16
*)(o
+ 2));
405 char proto_name
[] = "0x0000";
409 if (response
&& response
!= ConfigNak
) // rej already queued
412 if (proto
== PPPCHAP
)
413 strcpy(proto_name
, "CHAP");
415 sprintf(proto_name
, "%#4.4x", proto
);
417 LOG(2, session
[s
].ip
, s
, t
, " Remote requesting %s authentication. Rejecting.\n", proto_name
);
421 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
423 response
= *q
++ = ConfigNak
;
426 if ((q
- b
+ length
) > sizeof(b
))
428 LOG(2, session
[s
].ip
, s
, t
, "LCP overflow for %s ConfigNak.\n", proto_name
);
432 memcpy(q
, o
, length
);
433 *(u16
*)(q
+= 2) = htons(PPPPAP
); // NAK -> Use PAP instead
438 case 5: // Magic-Number
439 magicno
= ntohl(*(u32
*)(o
+ 2));
442 case 4: // Quality-Protocol
443 case 7: // Protocol-Field-Compression
444 case 8: // Address-And-Control-Field-Compression
447 default: // Reject any unknown options
448 LOG(2, session
[s
].ip
, s
, t
, " Rejecting PPP LCP Option type %d\n", type
);
449 if (!response
|| response
!= ConfigRej
) // drop nak in favour of rej
451 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
453 response
= *q
++ = ConfigRej
;
456 if ((q
- b
+ length
) > sizeof(b
))
458 LOG(2, session
[s
].ip
, s
, t
, "LCP overflow for ConfigRej (type=%d).\n", type
);
462 memcpy(q
, o
, length
);
471 // Send back a ConfigAck
472 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
474 response
= *q
= ConfigAck
;
477 LOG(3, session
[s
].ip
, s
, t
, "Sending %s\n", ppp_lcp_types
[response
]);
478 tunnelsend(b
, l
+ (q
- b
), t
);
480 if (!(session
[s
].flags
& SF_LCP_ACKED
))
483 else if (*p
== ConfigNak
)
485 LOG(1, session
[s
].ip
, s
, t
, "Remote end sent a ConfigNak. Ignoring\n");
486 if (config
->debug
> 3) dumplcp(p
, l
);
489 else if (*p
== TerminateReq
)
491 LOG(3, session
[s
].ip
, s
, t
, "LCP: Received TerminateReq. Sending TerminateAck\n");
492 *p
= TerminateAck
; // close
493 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
495 tunnelsend(b
, l
+ (q
- b
), t
); // send it
496 sessionshutdown(s
, "Remote end closed connection.");
498 else if (*p
== TerminateAck
)
500 sessionshutdown(s
, "Connection closed.");
502 else if (*p
== EchoReq
)
504 LOG(5, session
[s
].ip
, s
, t
, "LCP: Received EchoReq. Sending EchoReply\n");
505 *p
= EchoReply
; // reply
506 *(u32
*) (p
+ 4) = htonl(session
[s
].magic
); // our magic number
507 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
509 tunnelsend(b
, l
+ (q
- b
), t
); // send it
511 else if (*p
== EchoReply
)
513 // Ignore it, last_packet time is set earlier than this.
515 else if (*p
== IdentRequest
)
520 LOG(1, 0, s
, t
, "Truncated Ident Packet (length=%d) to 1400 bytes\n", l
);
523 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
525 LOG_HEX(5, "LCPIdentRej", q
, l
+ 4);
526 tunnelsend(b
, 12 + 4 + l
, t
);
530 LOG(1, session
[s
].ip
, s
, t
, "Unexpected LCP code %d\n", *p
);
531 STAT(tunnel_rx_errors
);
536 // find a PPP option, returns point to option, or 0 if not found
537 static u8
*findppp(u8
*b
, u8 mtype
)
539 u16 l
= ntohs(*(u16
*) (b
+ 2));
546 if (l
< b
[1] || !b
[1])
556 // Process IPCP messages
557 void processipcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
561 CSTAT(call_processipcp
);
563 LOG_HEX(5, "IPCP", p
, l
);
566 LOG(1, 0, s
, t
, "Short IPCP %d bytes\n", l
);
567 STAT(tunnel_rx_errors
);
571 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
573 LOG(1, 0, s
, t
, "Length mismatch IPCP %u/%u\n", hl
, l
);
574 STAT(tunnel_rx_errors
);
581 // happy with our IPCP
582 u16 r
= session
[s
].radius
;
583 if ((!r
|| radius
[r
].state
== RADIUSIPCP
) && !session
[s
].walled_garden
)
588 radiussend(r
, RADIUSSTART
); // send radius start, having got IPCP at last
590 session
[s
].flags
|= SF_IPCP_ACKED
;
592 LOG(3, session
[s
].ip
, s
, t
, "IPCP Acked, session is now active\n");
594 // clear LCP_ACKED/CCP_ACKED flag for possible fast renegotiaion for routers
595 session
[s
].flags
&= ~(SF_LCP_ACKED
|SF_CCP_ACKED
);
601 LOG(1, 0, s
, t
, "Unexpected IPCP code %d\n", *p
);
602 STAT(tunnel_rx_errors
);
605 LOG(4, session
[s
].ip
, s
, t
, "IPCP ConfigReq received\n");
609 LOG(3, 0, s
, t
, "Waiting on radius reply\n");
610 return; // have to wait on RADIUS reply
612 // form a config reply quoting the IP in the session
620 while (q
< i
&& q
[1])
622 if (*q
!= 0x81 && *q
!= 0x83 && *q
!= 3)
631 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
636 while (p
< i
&& p
[1])
638 if (*p
!= 0x81 && *p
!= 0x83 && *p
!= 3)
640 LOG(2, 0, s
, t
, "IPCP reject %d\n", *p
);
641 memcpy(q
+ n
, p
, p
[1]);
646 *(u16
*) (q
+ 2) = htons(n
);
647 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigRej\n");
648 tunnelsend(b
, n
+ (q
- b
), t
); // send it
652 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigAck\n");
654 if ((i
= findppp(p
, 0x81))) // Primary DNS address
656 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns1
))
658 *(u32
*) (i
+ 2) = htonl(session
[s
].dns1
);
660 LOG(5, session
[s
].ip
, s
, t
, " DNS1 = %s\n", inet_toa(session
[s
].dns1
));
663 if ((i
= findppp(p
, 0x83))) // Secondary DNS address (TBA, is it)
665 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns2
))
667 *(u32
*) (i
+ 2) = htonl(session
[s
].dns2
);
669 LOG(5, session
[s
].ip
, s
, t
, " DNS2 = %s\n", inet_toa(session
[s
].dns2
));
672 i
= findppp(p
, 3); // IP address
675 LOG(1, 0, s
, t
, "No IP in IPCP request\n");
676 STAT(tunnel_rx_errors
);
679 if (*(u32
*) (i
+ 2) != htonl(session
[s
].ip
))
681 *(u32
*) (i
+ 2) = htonl(session
[s
].ip
);
683 LOG(4, session
[s
].ip
, s
, t
, " No, a ConfigNak, client is requesting IP - sending %s\n",
684 inet_toa(htonl(session
[s
].ip
)));
686 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
689 tunnelsend(b
, l
+ (q
- b
), t
); // send it
694 // process IP packet received
696 // This MUST be called with at least 4 byte behind 'p'.
697 // (i.e. this routine writes to p[-4]).
698 void processipin(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
702 CSTAT(call_processipin
);
704 LOG_HEX(5, "IP", p
, l
);
706 ip
= ntohl(*(u32
*)(p
+ 12));
710 LOG(1, ip
, s
, t
, "IP packet too long %d\n", l
);
711 STAT(tunnel_rx_errors
);
715 // no spoof (do sessionbyip to handled statically routed subnets)
716 if (ip
!= session
[s
].ip
&& sessionbyip(htonl(ip
)) != s
)
718 LOG(5, ip
, s
, t
, "Dropping packet with spoofed IP %s\n", inet_toa(htonl(ip
)));
722 // run access-list if any
723 if (session
[s
].filter_in
&& !ip_filter(p
, l
, session
[s
].filter_in
- 1))
726 // Add on the tun header
728 *(u32
*)p
= htonl(0x00000800);
731 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) { // Are we throttled and a slave?
732 master_throttle_packet(session
[s
].tbf_in
, p
, l
); // Pass it to the master for handling.
736 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) { // Are we throttled and a master?? actually handle the throttled packets.
737 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
742 if (tun_write(p
, l
) < 0)
745 LOG(0, 0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
746 l
, strerror(errno
), tunfd
, p
);
751 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
753 // Snooping this session
754 snoop_send_packet(p
+ 4, l
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
757 session
[s
].cin
+= l
- 4;
758 session
[s
].total_cin
+= l
- 4;
759 sess_count
[s
].cin
+= l
- 4;
764 STAT(tun_tx_packets
);
765 INC_STAT(tun_tx_bytes
, l
- 4);
769 // Helper routine for the TBF filters.
770 // Used to send queued data in from the user.
772 void send_ipin(sessionidt s
, u8
*buf
, int len
)
774 LOG_HEX(5, "IP in throttled", buf
, len
);
776 if (write(tunfd
, buf
, len
) < 0)
779 LOG(0, 0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
780 len
, strerror(errno
), tunfd
, buf
);
785 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
787 // Snooping this session
788 snoop_send_packet(buf
+ 4, len
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
791 // Increment packet counters
792 session
[s
].cin
+= len
- 4;
793 session
[s
].total_cin
+= len
- 4;
794 sess_count
[s
].cin
+= len
- 4;
799 STAT(tun_tx_packets
);
800 INC_STAT(tun_tx_bytes
, len
- 4);
804 // Process CCP messages
805 void processccp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
810 CSTAT(call_processccp
);
812 LOG_HEX(5, "CCP", p
, l
);
813 switch (l
> 1 ? *p
: 0)
816 session
[s
].flags
|= SF_CCP_ACKED
;
820 if (l
< 6) // accept no compression
826 // compression requested--reject
829 // send CCP request for no compression for our end if not negotiated
830 if (!(session
[s
].flags
& SF_CCP_ACKED
))
841 LOG(1, 0, s
, t
, "Unexpected CCP request code %d\n", *p
);
843 LOG(1, 0, s
, t
, "Short CCP packet\n");
845 STAT(tunnel_rx_errors
);
849 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPCCP
)))
852 tunnelsend(b
, l
+ (q
- b
), t
); // send it
855 // send a CHAP PP packet
856 void sendchap(tunnelidt t
, sessionidt s
)
859 u16 r
= session
[s
].radius
;
862 CSTAT(call_sendchap
);
866 LOG(1, 0, s
, t
, "No RADIUS to send challenge\n");
867 STAT(tunnel_tx_errors
);
870 LOG(1, 0, s
, t
, "Send CHAP challenge\n");
874 for (n
= 0; n
< 15; n
++)
875 radius
[r
].auth
[n
] = rand();
877 radius
[r
].chap
= 1; // CHAP not PAP
879 if (radius
[r
].state
!= RADIUSCHAP
)
881 radius
[r
].state
= RADIUSCHAP
;
882 radius
[r
].retry
= backoff(radius
[r
].try++);
883 if (radius
[r
].try > 5)
885 sessionshutdown(s
, "Timeout CHAP");
886 STAT(tunnel_tx_errors
);
889 q
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPCHAP
);
893 q
[1] = radius
[r
].id
; // ID
895 memcpy(q
+ 5, radius
[r
].auth
, 16); // challenge
896 strcpy(q
+ 21, hostname
); // our name
897 *(u16
*) (q
+ 2) = htons(strlen(hostname
) + 21); // length
898 tunnelsend(b
, strlen(hostname
) + 21 + (q
- b
), t
); // send it
901 // fill in a L2TP message with a PPP frame,
902 // copies existing PPP message and changes magic number if seen
903 // returns start of PPP frame
904 u8
*makeppp(u8
*b
, int size
, u8
*p
, int l
, tunnelidt t
, sessionidt s
, u16 mtype
)
906 if (size
< 12) // Need more space than this!!
908 static int backtrace_count
= 0;
909 LOG(0, session
[s
].ip
, s
, t
, "makeppp buffer too small for L2TP header (size=%d)\n", size
);
910 log_backtrace(backtrace_count
, 5)
914 *(u16
*) (b
+ 0) = htons(0x0002); // L2TP with no options
915 *(u16
*) (b
+ 2) = htons(tunnel
[t
].far
); // tunnel
916 *(u16
*) (b
+ 4) = htons(session
[s
].far
); // session
918 if (mtype
== PPPLCP
|| !(session
[s
].l2tp_flags
& SESSIONACFC
))
920 *(u16
*) b
= htons(0xFF03); // HDLC header
923 if (mtype
< 0x100 && session
[s
].l2tp_flags
& SESSIONPFC
)
927 *(u16
*) b
= htons(mtype
);
933 static int backtrace_count
= 0;
934 LOG(2, session
[s
].ip
, s
, t
, "makeppp would overflow buffer (size=%d, header+payload=%d)\n", size
, l
+ 12);
935 log_backtrace(backtrace_count
, 5)
945 // Send initial LCP ConfigReq for PAP, set magic no.
946 void initlcp(tunnelidt t
, sessionidt s
)
950 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
)))
953 LOG(4, 0, s
, t
, "Sending LCP ConfigReq for PAP\n");
955 *(u8
*)(q
+ 1) = (time_now
% 255) + 1; // ID
956 *(u16
*)(q
+ 2) = htons(14); // Length
959 *(u32
*)(q
+ 6) = htonl(session
[s
].magic
);
962 *(u16
*)(q
+ 12) = htons(PPPPAP
); // PAP
964 LOG_HEX(5, "PPPLCP", q
, 14);
965 tunnelsend(b
, (q
- b
) + 14, t
);
968 // Send CCP request for no compression
969 static void initccp(tunnelidt t
, sessionidt s
)
973 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPCCP
)))
976 LOG(4, 0, s
, t
, "Sending CCP ConfigReq for no compression\n");
978 *(u8
*)(q
+ 1) = (time_now
% 255) + 1; // ID
979 *(u16
*)(q
+ 2) = htons(4); // Length
981 LOG_HEX(5, "PPPCCP", q
, 4);
982 tunnelsend(b
, (q
- b
) + 4 , t
);