9467ef1ba6bf37a75e2ce1fa797f6c8681be42bd
3 char const *cvs_id_ppp
= "$Id: ppp.c,v 1.28 2004-11-25 02:45: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 // Process PAP messages
27 void processpap(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
33 CSTAT(call_processpap
);
35 LOG_HEX(5, "PAP", p
, l
);
38 LOG(1, 0, s
, t
, "Short PAP %u bytes\n", l
);
39 STAT(tunnel_rx_errors
);
43 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
45 LOG(1, 0, s
, t
, "Length mismatch PAP %u/%u\n", hl
, l
);
46 STAT(tunnel_rx_errors
);
53 LOG(1, 0, s
, t
, "Unexpected PAP code %d\n", *p
);
54 STAT(tunnel_rx_errors
);
61 if (*b
&& *b
< sizeof(user
))
62 memcpy(user
, b
+ 1, *b
);
65 if (*b
&& *b
< sizeof(pass
))
66 memcpy(pass
, b
+ 1, *b
);
68 LOG(3, 0, s
, t
, "PAP login %s/%s\n", user
, pass
);
70 if (session
[s
].ip
|| !session
[s
].radius
)
72 // respond now, either no RADIUS available or already authenticated
75 u8
*p
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPPAP
);
81 *p
= 3; // cant authorise
83 *(u16
*) (p
+ 2) = htons(5); // length
84 p
[4] = 0; // no message
87 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
);
88 session
[s
].flags
&= ~SF_IPCP_ACKED
;
92 LOG(1, 0, s
, t
, "No radius session available to authenticate session...\n");
94 LOG(3, 0, s
, t
, "Fallback response to PAP (%s)\n", (session
[s
].ip
) ? "ACK" : "NAK");
95 tunnelsend(b
, 5 + (p
- b
), t
); // send it
99 // set up RADIUS request
100 u16 r
= session
[s
].radius
;
102 // Run PRE_AUTH plugins
103 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], strdup(user
), strdup(pass
), PPPPAP
, 1 };
104 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
105 if (!packet
.continue_auth
)
107 LOG(3, 0, s
, t
, "A plugin rejected PRE_AUTH\n");
108 if (packet
.username
) free(packet
.username
);
109 if (packet
.password
) free(packet
.password
);
113 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
114 strncpy(radius
[r
].pass
, packet
.password
, sizeof(radius
[r
].pass
) - 1);
116 free(packet
.username
);
117 free(packet
.password
);
120 LOG(3, 0, s
, t
, "Sending login for %s/%s to radius\n", user
, pass
);
121 radiussend(r
, RADIUSAUTH
);
125 // Process CHAP messages
126 void processchap(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
131 CSTAT(call_processchap
);
133 LOG_HEX(5, "CHAP", p
, l
);
134 r
= session
[s
].radius
;
137 LOG(1, 0, s
, t
, "Unexpected CHAP message\n");
139 // FIXME: Need to drop the session here.
141 STAT(tunnel_rx_errors
);
147 LOG(1, 0, s
, t
, "Short CHAP %u bytes\n", l
);
148 STAT(tunnel_rx_errors
);
152 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
154 LOG(1, 0, s
, t
, "Length mismatch CHAP %u/%u\n", hl
, l
);
155 STAT(tunnel_rx_errors
);
162 LOG(1, 0, s
, t
, "Unexpected CHAP response code %d\n", *p
);
163 STAT(tunnel_rx_errors
);
166 if (p
[1] != radius
[r
].id
)
168 LOG(1, 0, s
, t
, "Wrong CHAP response ID %d (should be %d) (%d)\n", p
[1], radius
[r
].id
, r
);
169 STAT(tunnel_rx_errors
);
173 if (l
< 5 || p
[4] != 16)
175 LOG(1, 0, s
, t
, "Bad CHAP response length %d\n", l
< 5 ? -1 : p
[4]);
176 STAT(tunnel_rx_errors
);
182 if (l
< 16 || l
- 16 >= sizeof(session
[s
].user
))
184 LOG(1, 0, s
, t
, "CHAP user too long %d\n", l
- 16);
185 STAT(tunnel_rx_errors
);
189 // Run PRE_AUTH plugins
191 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], NULL
, NULL
, PPPCHAP
, 1 };
193 packet
.password
= calloc(17, 1);
194 memcpy(packet
.password
, p
, 16);
199 packet
.username
= calloc(l
+ 1, 1);
200 memcpy(packet
.username
, p
, l
);
202 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
203 if (!packet
.continue_auth
)
205 LOG(3, 0, s
, t
, "A plugin rejected PRE_AUTH\n");
206 if (packet
.username
) free(packet
.username
);
207 if (packet
.password
) free(packet
.password
);
211 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
212 memcpy(radius
[r
].pass
, packet
.password
, 16);
214 free(packet
.username
);
215 free(packet
.password
);
219 LOG(3, 0, s
, t
, "CHAP login %s\n", session
[s
].user
);
220 radiussend(r
, RADIUSAUTH
);
223 static char *ppp_lcp_types
[] = {
239 static void dumplcp(u8
*p
, int l
)
244 LOG_HEX(5, "PPP LCP Packet", p
, l
);
245 LOG(4, 0, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p
, ppp_lcp_types
[(int)*p
], ntohs( ((u16
*) p
)[1]) );
246 LOG(4, 0, 0, 0, "Length: %d\n", l
);
247 if (*p
!= ConfigReq
&& *p
!= ConfigRej
&& *p
!= ConfigAck
)
256 LOG(4, 0, 0, 0, " Option length is %d...\n", length
);
261 LOG(4, 0, 0, 0, " Option type is 0...\n");
268 case 1: // Maximum-Receive-Unit
270 LOG(4, 0, 0, 0, " %s %d\n", lcp_types
[type
], ntohs(*(u16
*)(o
+ 2)));
272 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
274 case 2: // Async-Control-Character-Map
277 u32 asyncmap
= ntohl(*(u32
*)(o
+ 2));
278 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], asyncmap
);
281 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
283 case 3: // Authentication-Protocol
286 int proto
= ntohs(*(u16
*)(o
+ 2));
287 LOG(4, 0, 0, 0, " %s 0x%x (%s)\n", lcp_types
[type
], proto
,
288 proto
== PPPCHAP
? "CHAP" :
289 proto
== PPPPAP
? "PAP" : "UNKNOWN");
292 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
294 case 4: // Quality-Protocol
296 u32 qp
= ntohl(*(u32
*)(o
+ 2));
297 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], qp
);
300 case 5: // Magic-Number
303 u32 magicno
= ntohl(*(u32
*)(o
+ 2));
304 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], magicno
);
307 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
309 case 7: // Protocol-Field-Compression
310 case 8: // Address-And-Control-Field-Compression
311 LOG(4, 0, 0, 0, " %s\n", lcp_types
[type
]);
314 LOG(2, 0, 0, 0, " Unknown PPP LCP Option type %d\n", type
);
322 // Process LCP messages
323 void processlcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
330 CSTAT(call_processlcp
);
332 LOG_HEX(5, "LCP", p
, l
);
335 LOG(1, session
[s
].ip
, s
, t
, "Short LCP %d bytes\n", l
);
336 STAT(tunnel_rx_errors
);
340 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
342 LOG(1, 0, s
, t
, "Length mismatch LCP %u/%u\n", hl
, l
);
343 STAT(tunnel_rx_errors
);
350 LOG(3, session
[s
].ip
, s
, t
, "LCP: Discarding ConfigAck\n");
351 session
[s
].flags
|= SF_LCP_ACKED
;
353 else if (*p
== ConfigReq
)
359 LOG(3, session
[s
].ip
, s
, t
, "LCP: ConfigReq (%d bytes)...\n", l
);
360 if (config
->debug
> 3) dumplcp(p
, l
);
366 if (length
== 0 || type
== 0 || x
< length
) break;
369 case 1: // Maximum-Receive-Unit
370 session
[s
].mru
= ntohs(*(u16
*)(o
+ 2));
373 case 2: // Async-Control-Character-Map
374 if (!ntohl(*(u32
*)(o
+ 2))) // all bits zero is OK
377 if (response
&& response
!= ConfigNak
) // rej already queued
380 LOG(2, session
[s
].ip
, s
, t
, " Remote requesting asyncmap. Rejecting.\n");
383 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
385 response
= *q
++ = ConfigNak
;
388 if ((q
- b
+ 11) > sizeof(b
))
390 LOG(2, session
[s
].ip
, s
, t
, "LCP overflow for asyncmap ConfigNak.\n");
396 memset(q
, 0, 4); // asyncmap 0
400 case 3: // Authentication-Protocol
402 int proto
= ntohs(*(u16
*)(o
+ 2));
403 char proto_name
[] = "0x0000";
407 if (response
&& response
!= ConfigNak
) // rej already queued
410 if (proto
== PPPCHAP
)
411 strcpy(proto_name
, "CHAP");
413 sprintf(proto_name
, "%#4.4x", proto
);
415 LOG(2, session
[s
].ip
, s
, t
, " Remote requesting %s authentication. Rejecting.\n", proto_name
);
419 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
421 response
= *q
++ = ConfigNak
;
424 if ((q
- b
+ length
) > sizeof(b
))
426 LOG(2, session
[s
].ip
, s
, t
, "LCP overflow for %s ConfigNak.\n", proto_name
);
430 memcpy(q
, o
, length
);
431 *(u16
*)(q
+= 2) = htons(PPPPAP
); // NAK -> Use PAP instead
436 case 5: // Magic-Number
437 magicno
= ntohl(*(u32
*)(o
+ 2));
440 case 4: // Quality-Protocol
441 case 7: // Protocol-Field-Compression
442 case 8: // Address-And-Control-Field-Compression
445 default: // Reject any unknown options
446 LOG(2, session
[s
].ip
, s
, t
, " Rejecting PPP LCP Option type %d\n", type
);
447 if (!response
|| response
!= ConfigRej
) // drop nak in favour of rej
449 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
451 response
= *q
++ = ConfigRej
;
454 if ((q
- b
+ length
) > sizeof(b
))
456 LOG(2, session
[s
].ip
, s
, t
, "LCP overflow for ConfigRej (type=%d).\n", type
);
460 memcpy(q
, o
, length
);
469 // Send back a ConfigAck
470 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
472 response
= *q
= ConfigAck
;
475 LOG(3, session
[s
].ip
, s
, t
, "Sending %s\n", ppp_lcp_types
[response
]);
476 tunnelsend(b
, l
+ (q
- b
), t
);
478 if (!(session
[s
].flags
& SF_LCP_ACKED
))
481 else if (*p
== ConfigNak
)
483 LOG(1, session
[s
].ip
, s
, t
, "Remote end sent a ConfigNak. Ignoring\n");
484 if (config
->debug
> 3) dumplcp(p
, l
);
487 else if (*p
== TerminateReq
)
489 LOG(3, session
[s
].ip
, s
, t
, "LCP: Received TerminateReq. Sending TerminateAck\n");
490 *p
= TerminateAck
; // close
491 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
493 tunnelsend(b
, l
+ (q
- b
), t
); // send it
494 sessionshutdown(s
, "Remote end closed connection.");
496 else if (*p
== TerminateAck
)
498 sessionshutdown(s
, "Connection closed.");
500 else if (*p
== EchoReq
)
502 LOG(5, session
[s
].ip
, s
, t
, "LCP: Received EchoReq. Sending EchoReply\n");
503 *p
= EchoReply
; // reply
504 *(u32
*) (p
+ 4) = htonl(session
[s
].magic
); // our magic number
505 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
507 tunnelsend(b
, l
+ (q
- b
), t
); // send it
509 else if (*p
== EchoReply
)
511 // Ignore it, last_packet time is set earlier than this.
513 else if (*p
== IdentRequest
)
518 LOG(1, 0, s
, t
, "Truncated Ident Packet (length=%d) to 1400 bytes\n", l
);
521 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
523 LOG_HEX(5, "LCPIdentRej", q
, l
+ 4);
524 tunnelsend(b
, 12 + 4 + l
, t
);
528 LOG(1, session
[s
].ip
, s
, t
, "Unexpected LCP code %d\n", *p
);
529 STAT(tunnel_rx_errors
);
534 // find a PPP option, returns point to option, or 0 if not found
535 static u8
*findppp(u8
*b
, u8 mtype
)
537 u16 l
= ntohs(*(u16
*) (b
+ 2));
544 if (l
< b
[1] || !b
[1])
554 // Process IPCP messages
555 void processipcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
559 CSTAT(call_processipcp
);
561 LOG_HEX(5, "IPCP", p
, l
);
564 LOG(1, 0, s
, t
, "Short IPCP %d bytes\n", l
);
565 STAT(tunnel_rx_errors
);
569 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
571 LOG(1, 0, s
, t
, "Length mismatch IPCP %u/%u\n", hl
, l
);
572 STAT(tunnel_rx_errors
);
579 // happy with our IPCP
580 u16 r
= session
[s
].radius
;
581 if ((!r
|| radius
[r
].state
== RADIUSIPCP
) && !session
[s
].walled_garden
)
586 radiussend(r
, RADIUSSTART
); // send radius start, having got IPCP at last
588 session
[s
].flags
|= SF_IPCP_ACKED
;
590 LOG(3, session
[s
].ip
, s
, t
, "IPCP Acked, session is now active\n");
592 // clear LCP_ACKED flag for possible fast renegotiaion for routers
593 session
[s
].flags
&= ~SF_LCP_ACKED
;
599 LOG(1, 0, s
, t
, "Unexpected IPCP code %d\n", *p
);
600 STAT(tunnel_rx_errors
);
603 LOG(4, session
[s
].ip
, s
, t
, "IPCP ConfigReq received\n");
607 LOG(3, 0, s
, t
, "Waiting on radius reply\n");
608 return; // have to wait on RADIUS reply
610 // form a config reply quoting the IP in the session
618 while (q
< i
&& q
[1])
620 if (*q
!= 0x81 && *q
!= 0x83 && *q
!= 3)
629 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
634 while (p
< i
&& p
[1])
636 if (*p
!= 0x81 && *p
!= 0x83 && *p
!= 3)
638 LOG(2, 0, s
, t
, "IPCP reject %d\n", *p
);
639 memcpy(q
+ n
, p
, p
[1]);
644 *(u16
*) (q
+ 2) = htons(n
);
645 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigRej\n");
646 tunnelsend(b
, n
+ (q
- b
), t
); // send it
650 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigAck\n");
652 if ((i
= findppp(p
, 0x81))) // Primary DNS address
654 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns1
))
656 *(u32
*) (i
+ 2) = htonl(session
[s
].dns1
);
658 LOG(5, session
[s
].ip
, s
, t
, " DNS1 = %s\n", inet_toa(session
[s
].dns1
));
661 if ((i
= findppp(p
, 0x83))) // Secondary DNS address (TBA, is it)
663 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns2
))
665 *(u32
*) (i
+ 2) = htonl(session
[s
].dns2
);
667 LOG(5, session
[s
].ip
, s
, t
, " DNS2 = %s\n", inet_toa(session
[s
].dns2
));
670 i
= findppp(p
, 3); // IP address
673 LOG(1, 0, s
, t
, "No IP in IPCP request\n");
674 STAT(tunnel_rx_errors
);
677 if (*(u32
*) (i
+ 2) != htonl(session
[s
].ip
))
679 *(u32
*) (i
+ 2) = htonl(session
[s
].ip
);
681 LOG(4, session
[s
].ip
, s
, t
, " No, a ConfigNak, client is requesting IP - sending %s\n",
682 inet_toa(htonl(session
[s
].ip
)));
684 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
687 tunnelsend(b
, l
+ (q
- b
), t
); // send it
692 // process IP packet received
694 // This MUST be called with at least 4 byte behind 'p'.
695 // (i.e. this routine writes to p[-4]).
696 void processipin(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
700 CSTAT(call_processipin
);
702 LOG_HEX(5, "IP", p
, l
);
704 ip
= ntohl(*(u32
*)(p
+ 12));
708 LOG(1, ip
, s
, t
, "IP packet too long %d\n", l
);
709 STAT(tunnel_rx_errors
);
713 // no spoof (do sessionbyip to handled statically routed subnets)
714 if (ip
!= session
[s
].ip
&& sessionbyip(htonl(ip
)) != s
)
716 LOG(5, ip
, s
, t
, "Dropping packet with spoofed IP %s\n", inet_toa(htonl(ip
)));
720 // Add on the tun header
722 *(u32
*)p
= htonl(0x00000800);
725 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) { // Are we throttled and a slave?
726 master_throttle_packet(session
[s
].tbf_in
, p
, l
); // Pass it to the master for handling.
730 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) { // Are we throttled and a master?? actually handle the throttled packets.
731 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
736 if (tun_write(p
, l
) < 0)
739 LOG(0, 0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
740 l
, strerror(errno
), tunfd
, p
);
745 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
747 // Snooping this session
748 snoop_send_packet(p
+ 4, l
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
751 session
[s
].cin
+= l
- 4;
752 session
[s
].total_cin
+= l
- 4;
753 sess_count
[s
].cin
+= l
- 4;
758 STAT(tun_tx_packets
);
759 INC_STAT(tun_tx_bytes
, l
- 4);
763 // Helper routine for the TBF filters.
764 // Used to send queued data in from the user.
766 void send_ipin(sessionidt s
, u8
*buf
, int len
)
768 LOG_HEX(5, "IP in throttled", buf
, len
);
770 if (write(tunfd
, buf
, len
) < 0)
773 LOG(0, 0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
774 len
, strerror(errno
), tunfd
, buf
);
779 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
781 // Snooping this session
782 snoop_send_packet(buf
+ 4, len
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
785 // Increment packet counters
786 session
[s
].cin
+= len
- 4;
787 session
[s
].total_cin
+= len
- 4;
788 sess_count
[s
].cin
+= len
- 4;
793 STAT(tun_tx_packets
);
794 INC_STAT(tun_tx_bytes
, len
- 4);
798 // Process CCP messages
799 void processccp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
804 CSTAT(call_processccp
);
806 LOG_HEX(5, "CCP", p
, l
);
807 switch (l
> 1 ? *p
: 0)
811 *p
= ConfigAck
; // accept no compression
813 *p
= ConfigRej
; // reject
823 LOG(1, 0, s
, t
, "Unexpected CCP request code %d\n", *p
);
825 LOG(1, 0, s
, t
, "Short CCP packet\n");
827 STAT(tunnel_rx_errors
);
831 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPCCP
)))
834 tunnelsend(b
, l
+ (q
- b
), t
); // send it
837 // send a CHAP PP packet
838 void sendchap(tunnelidt t
, sessionidt s
)
841 u16 r
= session
[s
].radius
;
844 CSTAT(call_sendchap
);
848 LOG(1, 0, s
, t
, "No RADIUS to send challenge\n");
849 STAT(tunnel_tx_errors
);
852 LOG(1, 0, s
, t
, "Send CHAP challenge\n");
856 for (n
= 0; n
< 15; n
++)
857 radius
[r
].auth
[n
] = rand();
859 radius
[r
].chap
= 1; // CHAP not PAP
861 if (radius
[r
].state
!= RADIUSCHAP
)
863 radius
[r
].state
= RADIUSCHAP
;
864 radius
[r
].retry
= backoff(radius
[r
].try++);
865 if (radius
[r
].try > 5)
867 sessionshutdown(s
, "Timeout CHAP");
868 STAT(tunnel_tx_errors
);
871 q
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPCHAP
);
875 q
[1] = radius
[r
].id
; // ID
877 memcpy(q
+ 5, radius
[r
].auth
, 16); // challenge
878 strcpy(q
+ 21, hostname
); // our name
879 *(u16
*) (q
+ 2) = htons(strlen(hostname
) + 21); // length
880 tunnelsend(b
, strlen(hostname
) + 21 + (q
- b
), t
); // send it
883 // fill in a L2TP message with a PPP frame,
884 // copies existing PPP message and changes magic number if seen
885 // returns start of PPP frame
886 u8
*makeppp(u8
*b
, int size
, u8
*p
, int l
, tunnelidt t
, sessionidt s
, u16 mtype
)
888 if (size
< 12) // Need more space than this!!
890 static int backtrace_count
= 0;
891 LOG(0, session
[s
].ip
, s
, t
, "makeppp buffer too small for L2TP header (size=%d)\n", size
);
892 log_backtrace(backtrace_count
, 5)
896 *(u16
*) (b
+ 0) = htons(0x0002); // L2TP with no options
897 *(u16
*) (b
+ 2) = htons(tunnel
[t
].far
); // tunnel
898 *(u16
*) (b
+ 4) = htons(session
[s
].far
); // session
900 if (mtype
== PPPLCP
|| !(session
[s
].l2tp_flags
& SESSIONACFC
))
902 *(u16
*) b
= htons(0xFF03); // HDLC header
905 if (mtype
< 0x100 && session
[s
].l2tp_flags
& SESSIONPFC
)
909 *(u16
*) b
= htons(mtype
);
915 static int backtrace_count
= 0;
916 LOG(2, session
[s
].ip
, s
, t
, "makeppp would overflow buffer (size=%d, header+payload=%d)\n", size
, l
+ 12);
917 log_backtrace(backtrace_count
, 5)
927 // Send initial LCP ConfigReq
928 void initlcp(tunnelidt t
, sessionidt s
)
930 char b
[500] = {0}, *q
;
932 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
)))
935 LOG(4, 0, s
, t
, "Sending LCP ConfigReq for PAP\n");
937 *(u8
*)(q
+ 1) = (time_now
% 255) + 1; // ID
938 *(u16
*)(q
+ 2) = htons(14); // Length
941 *(u32
*)(q
+ 6) = htonl(session
[s
].magic
);
944 *(u16
*)(q
+ 12) = htons(PPPPAP
); // PAP
945 tunnelsend(b
, 12 + 14, t
);