809637cd0d212370546fb2b23f69e714850f7254
3 char const *cvs_id_ppp
= "$Id: ppp.c,v 1.24 2004/11/09 05:48:28 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 2: // Async-Control-Character-Map
281 u32 asyncmap
= ntohl(*(u32
*)(o
+ 2));
282 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], asyncmap
);
285 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
287 case 3: // Authentication-Protocol
290 int proto
= ntohs(*(u16
*)(o
+ 2));
291 LOG(4, 0, 0, 0, " %s 0x%x (%s)\n", lcp_types
[type
], proto
,
292 proto
== PPPCHAP
? "CHAP" :
293 proto
== PPPPAP
? "PAP" : "UNKNOWN");
296 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
298 case 4: // Quality-Protocol
300 u32 qp
= ntohl(*(u32
*)(o
+ 2));
301 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], qp
);
304 case 5: // Magic-Number
307 u32 magicno
= ntohl(*(u32
*)(o
+ 2));
308 LOG(4, 0, 0, 0, " %s %x\n", lcp_types
[type
], magicno
);
311 LOG(4, 0, 0, 0, " %s odd length %d\n", lcp_types
[type
], length
);
313 case 7: // Protocol-Field-Compression
314 case 8: // Address-And-Control-Field-Compression
315 LOG(4, 0, 0, 0, " %s\n", lcp_types
[type
]);
318 LOG(2, 0, 0, 0, " Unknown PPP LCP Option type %d\n", type
);
326 // Process LCP messages
327 void processlcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
334 CSTAT(call_processlcp
);
336 LOG_HEX(5, "LCP", p
, l
);
339 LOG(1, session
[s
].ip
, s
, t
, "Short LCP %d bytes\n", l
);
340 STAT(tunnel_rx_errors
);
344 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
346 LOG(1, 0, s
, t
, "Length mismatch LCP %u/%u\n", hl
, l
);
347 STAT(tunnel_rx_errors
);
354 LOG(3, session
[s
].ip
, s
, t
, "LCP: Discarding ConfigAck\n");
355 session
[s
].flags
|= SF_LCP_ACKED
;
357 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 || x
< length
) break;
373 case 1: // Maximum-Receive-Unit
374 session
[s
].mru
= ntohs(*(u16
*)(o
+ 2));
377 case 2: // Async-Control-Character-Map
378 if (!ntohl(*(u32
*)(o
+ 2))) // all bits zero is OK
381 if (response
&& response
!= ConfigNak
) // rej already queued
384 LOG(2, session
[s
].ip
, s
, t
, " Remote requesting asyncmap. Rejecting.\n");
387 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
390 LOG(2, session
[s
].ip
, s
, t
, " Failed to send packet.\n");
393 response
= *q
++ = ConfigNak
;
397 memset(q
, 0, 4); // asyncmap 0
401 case 3: // Authentication-Protocol
403 int proto
= ntohs(*(u16
*)(o
+ 2));
404 char proto_name
[] = "0x0000";
408 if (response
&& response
!= ConfigNak
) // rej already queued
411 if (proto
== PPPCHAP
)
412 strcpy(proto_name
, "CHAP");
414 sprintf(proto_name
, "%#4.4x", proto
);
416 LOG(2, session
[s
].ip
, s
, t
, " Remote requesting %s authentication. Rejecting.\n", proto_name
);
420 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
423 LOG(2, session
[s
].ip
, s
, t
, " Failed to send packet.\n");
426 response
= *q
++ = ConfigNak
;
428 memcpy(q
, o
, length
);
429 *(u16
*)(q
+= 2) = htons(PPPPAP
); // NAK -> Use PAP instead
434 case 5: // Magic-Number
435 magicno
= ntohl(*(u32
*)(o
+ 2));
438 case 4: // Quality-Protocol
439 case 7: // Protocol-Field-Compression
440 case 8: // Address-And-Control-Field-Compression
443 default: // Reject any unknown options
444 LOG(2, session
[s
].ip
, s
, t
, " Rejecting PPP LCP Option type %d\n", type
);
445 if (!response
|| response
!= ConfigRej
) // drop nak in favour of rej
447 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
450 LOG(2, session
[s
].ip
, s
, t
, " Failed to send packet.\n");
453 response
= *q
++ = ConfigRej
;
456 memcpy(q
, o
, length
);
465 // Send back a ConfigAck
466 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
469 LOG(3, session
[s
].ip
, s
, t
, " failed to create packet.\n");
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 *p
= TerminateAck
; // close
490 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
493 LOG(3, session
[s
].ip
, s
, t
, "Failed to create PPP packet in processlcp.\n");
496 LOG(3, session
[s
].ip
, s
, t
, "LCP: Received TerminateReq. Sending TerminateAck\n");
497 sessionshutdown(s
, "Remote end closed connection.");
498 tunnelsend(b
, l
+ (q
- b
), t
); // send it
500 else if (*p
== TerminateAck
)
502 sessionshutdown(s
, "Connection closed.");
504 else if (*p
== EchoReq
)
506 *p
= EchoReply
; // reply
507 *(u32
*) (p
+ 4) = htonl(session
[s
].magic
); // our magic number
508 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
511 LOG(3, session
[s
].ip
, s
, t
, " failed to send EchoReply.\n");
514 LOG(5, session
[s
].ip
, s
, t
, "LCP: Received EchoReq. Sending EchoReply\n");
515 tunnelsend(b
, l
+ (q
- b
), t
); // send it
517 else if (*p
== EchoReply
)
519 // Ignore it, last_packet time is set earlier than this.
521 else if (*p
== IdentRequest
)
526 LOG(1, 0, s
, t
, "Truncated Ident Packet (length=%d) to 1400 bytes\n", l
);
529 q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPLCP
);
532 LOG(3, session
[s
].ip
, s
, t
, "Failed to create IdentRej.\n");
535 LOG_HEX(5, "LCPIdentRej", q
, l
+ 4);
536 tunnelsend(b
, 12 + 4 + l
, t
);
540 LOG(1, session
[s
].ip
, s
, t
, "Unexpected LCP code %d\n", *p
);
541 STAT(tunnel_rx_errors
);
546 // Process IPCP messages
547 void processipcp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
551 CSTAT(call_processipcp
);
553 LOG_HEX(5, "IPCP", p
, l
);
556 LOG(1, 0, s
, t
, "Short IPCP %d bytes\n", l
);
557 STAT(tunnel_rx_errors
);
561 if ((hl
= ntohs(*(u16
*) (p
+ 2))) > l
)
563 LOG(1, 0, s
, t
, "Length mismatch IPCP %u/%u\n", hl
, l
);
564 STAT(tunnel_rx_errors
);
571 // happy with our IPCP
572 u16 r
= session
[s
].radius
;
573 if ((!r
|| radius
[r
].state
== RADIUSIPCP
) && !session
[s
].walled_garden
)
578 radiussend(r
, RADIUSSTART
); // send radius start, having got IPCP at last
580 session
[s
].flags
|= SF_IPCP_ACKED
;
582 LOG(3, session
[s
].ip
, s
, t
, "IPCP Acked, session is now active\n");
587 LOG(1, 0, s
, t
, "Unexpected IPCP code %d\n", *p
);
588 STAT(tunnel_rx_errors
);
591 LOG(4, session
[s
].ip
, s
, t
, "IPCP ConfigReq received\n");
595 LOG(3, 0, s
, t
, "Waiting on radius reply\n");
596 return; // have to wait on RADIUS reply
598 // form a config reply quoting the IP in the session
606 while (q
< i
&& q
[1])
608 if (*q
!= 0x81 && *q
!= 0x83 && *q
!= 3)
617 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
619 LOG(2, 0, s
, t
, "Failed to send IPCP ConfigRej\n");
624 while (p
< i
&& p
[1])
626 if (*p
!= 0x81 && *p
!= 0x83 && *p
!= 3)
628 LOG(2, 0, s
, t
, "IPCP reject %d\n", *p
);
629 memcpy(q
+ n
, p
, p
[1]);
634 *(u16
*) (q
+ 2) = htons(n
);
635 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigRej\n");
636 tunnelsend(b
, n
+ (q
- b
), t
); // send it
640 LOG(4, session
[s
].ip
, s
, t
, "Sending ConfigAck\n");
642 if ((i
= findppp(p
, 0x81))) // Primary DNS address
644 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns1
))
646 *(u32
*) (i
+ 2) = htonl(session
[s
].dns1
);
648 LOG(5, session
[s
].ip
, s
, t
, " DNS1 = %s\n", inet_toa(session
[s
].dns1
));
651 if ((i
= findppp(p
, 0x83))) // Secondary DNS address (TBA, is it)
653 if (*(u32
*) (i
+ 2) != htonl(session
[s
].dns2
))
655 *(u32
*) (i
+ 2) = htonl(session
[s
].dns2
);
657 LOG(5, session
[s
].ip
, s
, t
, " DNS2 = %s\n", inet_toa(session
[s
].dns2
));
660 i
= findppp(p
, 3); // IP address
663 LOG(1, 0, s
, t
, "No IP in IPCP request\n");
664 STAT(tunnel_rx_errors
);
667 if (*(u32
*) (i
+ 2) != htonl(session
[s
].ip
))
669 *(u32
*) (i
+ 2) = htonl(session
[s
].ip
);
671 LOG(4, session
[s
].ip
, s
, t
, " No, a ConfigNak, client is requesting IP - sending %s\n",
672 inet_toa(htonl(session
[s
].ip
)));
674 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPIPCP
)))
676 LOG(2, 0, s
, t
, " Failed to send IPCP packet.\n");
679 tunnelsend(b
, l
+ (q
- b
), t
); // send it
684 // process IP packet received
686 // This MUST be called with at least 4 byte behind 'p'.
687 // (i.e. this routine writes to p[-4]).
688 void processipin(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
692 CSTAT(call_processipin
);
694 LOG_HEX(5, "IP", p
, l
);
696 ip
= ntohl(*(u32
*)(p
+ 12));
700 LOG(1, ip
, s
, t
, "IP packet too long %d\n", l
);
701 STAT(tunnel_rx_errors
);
705 // no spoof (do sessionbyip to handled statically routed subnets)
706 if (ip
!= session
[s
].ip
&& sessionbyip(htonl(ip
)) != s
)
708 LOG(5, ip
, s
, t
, "Dropping packet with spoofed IP %s\n", inet_toa(htonl(ip
)));
712 // Add on the tun header
714 *(u32
*)p
= htonl(0x00000800);
717 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) { // Are we throttled and a slave?
718 master_throttle_packet(session
[s
].tbf_in
, p
, l
); // Pass it to the master for handling.
722 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) { // Are we throttled and a master?? actually handle the throttled packets.
723 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
728 if (tun_write(p
, l
) < 0)
731 LOG(0, 0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
732 l
, strerror(errno
), tunfd
, p
);
737 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
739 // Snooping this session
740 snoop_send_packet(p
+ 4, l
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
743 session
[s
].cin
+= l
- 4;
744 session
[s
].total_cin
+= l
- 4;
745 sess_count
[s
].cin
+= l
- 4;
750 STAT(tun_tx_packets
);
751 INC_STAT(tun_tx_bytes
, l
- 4);
755 // Helper routine for the TBF filters.
756 // Used to send queued data in from the user.
758 void send_ipin(sessionidt s
, u8
*buf
, int len
)
760 LOG_HEX(5, "IP in throttled", buf
, len
);
762 if (write(tunfd
, buf
, len
) < 0)
765 LOG(0, 0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
766 len
, strerror(errno
), tunfd
, buf
);
771 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
773 // Snooping this session
774 snoop_send_packet(buf
+ 4, len
- 4, session
[s
].snoop_ip
, session
[s
].snoop_port
);
777 // Increment packet counters
778 session
[s
].cin
+= len
- 4;
779 session
[s
].total_cin
+= len
- 4;
780 sess_count
[s
].cin
+= len
- 4;
785 STAT(tun_tx_packets
);
786 INC_STAT(tun_tx_bytes
, l
- 4);
790 // Process CCP messages
791 void processccp(tunnelidt t
, sessionidt s
, u8
*p
, u16 l
)
794 CSTAT(call_processccp
);
796 LOG_HEX(5, "CCP", p
, l
);
797 if (l
< 2 || (*p
!= ConfigReq
&& *p
!= TerminateReq
))
799 LOG(1, 0, s
, t
, "Unexpected CCP request code %d\n", *p
);
800 STAT(tunnel_rx_errors
);
811 *p
= ConfigAck
; // accept no compression
815 *p
= ConfigRej
; // reject
820 *p
= TerminateAck
; // close
821 if (!(q
= makeppp(b
, sizeof(b
), p
, l
, t
, s
, PPPCCP
)))
823 LOG(1,0,0,0, "Failed to send CCP packet.\n");
826 tunnelsend(b
, l
+ (q
- b
), t
); // send it
830 // send a CHAP PP packet
831 void sendchap(tunnelidt t
, sessionidt s
)
834 u16 r
= session
[s
].radius
;
837 CSTAT(call_sendchap
);
841 LOG(1, 0, s
, t
, "No RADIUS to send challenge\n");
842 STAT(tunnel_tx_errors
);
845 LOG(1, 0, s
, t
, "Send CHAP challenge\n");
849 for (n
= 0; n
< 15; n
++)
850 radius
[r
].auth
[n
] = rand();
852 radius
[r
].chap
= 1; // CHAP not PAP
854 if (radius
[r
].state
!= RADIUSCHAP
)
856 radius
[r
].state
= RADIUSCHAP
;
857 radius
[r
].retry
= backoff(radius
[r
].try++);
858 if (radius
[r
].try > 5)
860 sessionshutdown(s
, "Timeout CHAP");
861 STAT(tunnel_tx_errors
);
864 q
= makeppp(b
, sizeof(b
), 0, 0, t
, s
, PPPCHAP
);
867 LOG(1, 0, s
, t
, "failed to send CHAP challenge.\n");
871 q
[1] = radius
[r
].id
; // ID
873 memcpy(q
+ 5, radius
[r
].auth
, 16); // challenge
874 strcpy(q
+ 21, hostname
); // our name
875 *(u16
*) (q
+ 2) = htons(strlen(hostname
) + 21); // length
876 tunnelsend(b
, strlen(hostname
) + 21 + (q
- b
), t
); // send it
879 // fill in a L2TP message with a PPP frame,
880 // copies existing PPP message and changes magic number if seen
881 // returns start of PPP frame
882 u8
*makeppp(u8
*b
, int size
, u8
*p
, int l
, tunnelidt t
, sessionidt s
, u16 mtype
)
885 return NULL
; // Need more space than this!!
887 *(u16
*) (b
+ 0) = htons(0x0002); // L2TP with no options
888 *(u16
*) (b
+ 2) = htons(tunnel
[t
].far
); // tunnel
889 *(u16
*) (b
+ 4) = htons(session
[s
].far
); // session
891 if (mtype
== PPPLCP
|| !(session
[s
].l2tp_flags
& SESSIONACFC
))
893 *(u16
*) b
= htons(0xFF03); // HDLC header
896 if (mtype
< 0x100 && session
[s
].l2tp_flags
& SESSIONPFC
)
900 *(u16
*) b
= htons(mtype
);
905 LOG(3,0,0,0, "Would have overflowed the buffer in makeppp: size %d, len %d.\n", size
, l
);
906 return NULL
; // Run out of room to hold the packet!
913 // find a PPP option, returns point to option, or 0 if not found
914 u8
*findppp(u8
*b
, u8 mtype
)
916 u16 l
= ntohs(*(u16
*) (b
+ 2));
923 if (l
< b
[1] || !b
[1])
933 // Send initial LCP ConfigReq
934 void initlcp(tunnelidt t
, sessionidt s
)
936 char b
[500] = {0}, *q
;
938 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPLCP
);
941 LOG(1, 0, s
, t
, "Failed to send LCP ConfigReq.\n");
944 LOG(4, 0, s
, t
, "Sending LCP ConfigReq for PAP\n");
946 *(u8
*)(q
+ 1) = (time_now
% 255) + 1; // ID
947 *(u16
*)(q
+ 2) = htons(14); // Length
950 *(u32
*)(q
+ 6) = htonl(session
[s
].magic
);
953 *(u16
*)(q
+ 12) = htons(PPPPAP
); // PAP
954 tunnelsend(b
, 12 + 14, t
);
958 void sendccp(tunnelidt t
, sessionidt s
)
960 char *q
, b
[500] = {0};
962 q
= makeppp(b
, sizeof(b
), NULL
, 0, t
, s
, PPPCCP
);
964 *(u8
*)(q
+ 1) = (time_now
% 255) + 1; // ID
965 *(u16
*)(q
+ 2) = htons(4); // Length
966 LOG_HEX(5, "PPPCCP", q
, 4);
967 tunnelsend(b
, (q
- b
) + 4 , t
);