3 char const *cvs_id_ppp
= "$Id: ppp.c,v 1.104 2009/12/08 14:49:28 bodea Exp $";
11 #include "constants.h"
17 extern tunnelt
*tunnel
;
18 extern bundlet
*bundle
;
19 extern fragmentationt
*frag
;
20 extern sessiont
*session
;
21 extern radiust
*radius
;
23 extern char hostname
[];
24 extern uint32_t eth_tx
;
25 extern time_t time_now
;
26 extern configt
*config
;
28 static int add_lcp_auth(uint8_t *b
, int size
, int authtype
);
29 static bundleidt
new_bundle(void);
30 static int epdiscmp(epdist
, epdist
);
31 static void setepdis(epdist
*, epdist
);
32 static void ipcp_open(sessionidt s
, tunnelidt t
);
34 static int first_session_in_bundle(sessionidt s
)
37 for (i
= 1; i
< MAXBUNDLE
; i
++)
38 if (bundle
[i
].state
!= BUNDLEFREE
)
39 if (epdiscmp(session
[s
].epdis
,bundle
[i
].epdis
) && !strcmp(session
[s
].user
, bundle
[i
].user
))
44 // Process PAP messages
45 void processpap(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
54 LOG_HEX(5, "PAP", p
, l
);
57 LOG(1, s
, t
, "Short PAP %u bytes\n", l
);
58 STAT(tunnel_rx_errors
);
59 sessionshutdown(s
, "Short PAP packet.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
63 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
65 LOG(1, s
, t
, "Length mismatch PAP %u/%u\n", hl
, l
);
66 STAT(tunnel_rx_errors
);
67 sessionshutdown(s
, "PAP length mismatch.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
74 LOG(1, s
, t
, "Unexpected PAP code %d\n", *p
);
75 STAT(tunnel_rx_errors
);
76 sessionshutdown(s
, "Unexpected PAP code.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
80 if (session
[s
].ppp
.phase
!= Authenticate
)
82 LOG(2, s
, t
, "PAP ignored in %s phase\n", ppp_phase(session
[s
].ppp
.phase
));
89 user
[0] = pass
[0] = 0;
90 if (*b
&& *b
< sizeof(user
))
92 memcpy(user
, b
+ 1, *b
);
95 if (*b
&& *b
< sizeof(pass
))
97 memcpy(pass
, b
+ 1, *b
);
101 LOG(3, s
, t
, "PAP login %s/%s\n", user
, pass
);
104 if (session
[s
].ip
|| !(r
= radiusnew(s
)))
106 // respond now, either no RADIUS available or already authenticated
109 uint8_t *p
= makeppp(b
, sizeof(b
), 0, 0, s
, t
, PPPPAP
, 0, 0, 0);
115 *p
= 3; // cant authorise
117 *(uint16_t *) (p
+ 2) = htons(5); // length
118 p
[4] = 0; // no message
119 tunnelsend(b
, 5 + (p
- b
), t
); // send it
123 LOG(3, s
, t
, "Already an IP allocated: %s (%d)\n",
124 fmtaddr(htonl(session
[s
].ip
), 0), session
[s
].ip_pool_index
);
128 LOG(1, s
, t
, "No RADIUS session available to authenticate session...\n");
129 sessionshutdown(s
, "No free RADIUS sessions.", CDN_UNAVAILABLE
, TERM_SERVICE_UNAVAILABLE
);
134 // Run PRE_AUTH plugins
135 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], strdup(user
), strdup(pass
), PPPPAP
, 1 };
136 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
137 if (!packet
.continue_auth
)
139 LOG(3, s
, t
, "A plugin rejected PRE_AUTH\n");
140 if (packet
.username
) free(packet
.username
);
141 if (packet
.password
) free(packet
.password
);
145 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
146 strncpy(radius
[r
].pass
, packet
.password
, sizeof(radius
[r
].pass
) - 1);
148 free(packet
.username
);
149 free(packet
.password
);
152 LOG(3, s
, t
, "Sending login for %s/%s to RADIUS\n", user
, pass
);
153 if ((session
[s
].mrru
) && (!first_session_in_bundle(s
)))
154 radiussend(r
, RADIUSJUSTAUTH
);
156 radiussend(r
, RADIUSAUTH
);
160 // Process CHAP messages
161 void processchap(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
168 LOG_HEX(5, "CHAP", p
, l
);
172 LOG(1, s
, t
, "Short CHAP %u bytes\n", l
);
173 STAT(tunnel_rx_errors
);
174 sessionshutdown(s
, "Short CHAP packet.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
178 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
180 LOG(1, s
, t
, "Length mismatch CHAP %u/%u\n", hl
, l
);
181 STAT(tunnel_rx_errors
);
182 sessionshutdown(s
, "CHAP length mismatch.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
189 LOG(1, s
, t
, "Unexpected CHAP response code %d\n", *p
);
190 STAT(tunnel_rx_errors
);
191 sessionshutdown(s
, "CHAP length mismatch.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
195 if (session
[s
].ppp
.phase
!= Authenticate
)
197 LOG(2, s
, t
, "CHAP ignored in %s phase\n", ppp_phase(session
[s
].ppp
.phase
));
201 r
= sess_local
[s
].radius
;
204 LOG(3, s
, t
, "Unexpected CHAP message\n");
206 // Some modems (Netgear DM602, possibly others) persist in using CHAP even
207 // after ACKing our ConfigReq for PAP.
208 if (sess_local
[s
].lcp_authtype
== AUTHPAP
&& config
->radius_authtypes
& AUTHCHAP
)
210 sess_local
[s
].lcp_authtype
= AUTHCHAP
;
216 if (p
[1] != radius
[r
].id
)
218 LOG(1, s
, t
, "Wrong CHAP response ID %d (should be %d) (%d)\n", p
[1], radius
[r
].id
, r
);
219 STAT(tunnel_rx_errors
);
220 sessionshutdown(s
, "Unexpected CHAP response ID.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
224 if (l
< 5 || p
[4] != 16)
226 LOG(1, s
, t
, "Bad CHAP response length %d\n", l
< 5 ? -1 : p
[4]);
227 STAT(tunnel_rx_errors
);
228 sessionshutdown(s
, "Bad CHAP response length.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
234 if (l
< 16 || l
- 16 >= sizeof(session
[s
].user
))
236 LOG(1, s
, t
, "CHAP user too long %d\n", l
- 16);
237 STAT(tunnel_rx_errors
);
238 sessionshutdown(s
, "CHAP username too long.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
242 // Run PRE_AUTH plugins
244 struct param_pre_auth packet
= { &tunnel
[t
], &session
[s
], NULL
, NULL
, PPPCHAP
, 1 };
246 packet
.password
= calloc(17, 1);
247 memcpy(packet
.password
, p
, 16);
252 packet
.username
= calloc(l
+ 1, 1);
253 memcpy(packet
.username
, p
, l
);
255 run_plugins(PLUGIN_PRE_AUTH
, &packet
);
256 if (!packet
.continue_auth
)
258 LOG(3, s
, t
, "A plugin rejected PRE_AUTH\n");
259 if (packet
.username
) free(packet
.username
);
260 if (packet
.password
) free(packet
.password
);
264 strncpy(session
[s
].user
, packet
.username
, sizeof(session
[s
].user
) - 1);
265 memcpy(radius
[r
].pass
, packet
.password
, 16);
267 free(packet
.username
);
268 free(packet
.password
);
272 LOG(3, s
, t
, "CHAP login %s\n", session
[s
].user
);
273 if ((session
[s
].mrru
) && (!first_session_in_bundle(s
)))
274 radiussend(r
, RADIUSJUSTAUTH
);
276 radiussend(r
, RADIUSAUTH
);
279 static void dumplcp(uint8_t *p
, int l
)
282 uint8_t *o
= (p
+ 4);
284 LOG_HEX(5, "PPP LCP Packet", p
, l
);
285 LOG(4, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p
, ppp_code((int)*p
), ntohs( ((uint16_t *) p
)[1]) );
286 LOG(4, 0, 0, "Length: %d\n", l
);
287 if (*p
!= ConfigReq
&& *p
!= ConfigRej
&& *p
!= ConfigAck
)
296 LOG(4, 0, 0, " Option length is %d...\n", length
);
301 LOG(4, 0, 0, " Option type is 0...\n");
308 case 1: // Maximum-Receive-Unit
310 LOG(4, 0, 0, " %s %d\n", ppp_lcp_option(type
), ntohs(*(uint16_t *)(o
+ 2)));
312 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
314 case 2: // Async-Control-Character-Map
317 uint32_t asyncmap
= ntohl(*(uint32_t *)(o
+ 2));
318 LOG(4, 0, 0, " %s %x\n", ppp_lcp_option(type
), asyncmap
);
321 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
323 case 3: // Authentication-Protocol
326 int proto
= ntohs(*(uint16_t *)(o
+ 2));
327 LOG(4, 0, 0, " %s 0x%x (%s)\n", ppp_lcp_option(type
), proto
,
328 proto
== PPPPAP
? "PAP" : "UNSUPPORTED");
330 else if (length
== 5)
332 int proto
= ntohs(*(uint16_t *)(o
+ 2));
334 LOG(4, 0, 0, " %s 0x%x 0x%x (%s)\n", ppp_lcp_option(type
), proto
, algo
,
335 (proto
== PPPCHAP
&& algo
== 5) ? "CHAP MD5" : "UNSUPPORTED");
338 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
340 case 4: // Quality-Protocol
342 uint32_t qp
= ntohl(*(uint32_t *)(o
+ 2));
343 LOG(4, 0, 0, " %s %x\n", ppp_lcp_option(type
), qp
);
346 case 5: // Magic-Number
349 uint32_t magicno
= ntohl(*(uint32_t *)(o
+ 2));
350 LOG(4, 0, 0, " %s %x\n", ppp_lcp_option(type
), magicno
);
353 LOG(4, 0, 0, " %s odd length %d\n", ppp_lcp_option(type
), length
);
355 case 7: // Protocol-Field-Compression
356 case 8: // Address-And-Control-Field-Compression
357 LOG(4, 0, 0, " %s\n", ppp_lcp_option(type
));
360 LOG(2, 0, 0, " Unknown PPP LCP Option type %d\n", type
);
368 void lcp_open(sessionidt s
, tunnelidt t
)
370 // transition to Authentication or Network phase:
371 session
[s
].ppp
.phase
= sess_local
[s
].lcp_authtype
? Authenticate
: Network
;
373 LOG(3, s
, t
, "LCP: Opened, phase %s\n", ppp_phase(session
[s
].ppp
.phase
));
376 change_state(s
, lcp
, Opened
);
378 if (session
[s
].ppp
.phase
== Authenticate
)
380 if (sess_local
[s
].lcp_authtype
== AUTHCHAP
)
385 if(session
[s
].bundle
== 0 || bundle
[session
[s
].bundle
].num_of_links
== 1)
389 change_state(s
, ipcp
, RequestSent
);
390 // move to passive state for IPv6 (if configured), CCP
391 if (config
->ipv6_prefix
.s6_addr
[0])
392 change_state(s
, ipv6cp
, Stopped
);
394 change_state(s
, ipv6cp
, Closed
);
396 change_state(s
, ccp
, Stopped
);
400 sessionidt first_ses
= bundle
[session
[s
].bundle
].members
[0];
401 LOG(3, s
, t
, "MPPP: Skipping IPCP negotiation for session:%d, first session of bundle is:%d\n",s
,first_ses
);
407 static void lcp_restart(sessionidt s
)
409 session
[s
].ppp
.phase
= Establish
;
411 change_state(s
, ipcp
, Dead
);
412 change_state(s
, ipv6cp
, Dead
);
413 change_state(s
, ccp
, Dead
);
416 static uint8_t *ppp_conf_rej(sessionidt s
, uint8_t *buf
, size_t blen
, uint16_t mtype
,
417 uint8_t **response
, uint8_t *queued
, uint8_t *packet
, uint8_t *option
)
419 if (!*response
|| **response
!= ConfigRej
)
421 queued
= *response
= makeppp(buf
, blen
, packet
, 2, s
, session
[s
].tunnel
, mtype
, 0, 0, 0);
429 if ((queued
- buf
+ option
[1]) > blen
)
431 LOG(2, s
, session
[s
].tunnel
, "PPP overflow for ConfigRej (proto %u, option %u).\n", mtype
, *option
);
435 memcpy(queued
, option
, option
[1]);
436 return queued
+ option
[1];
439 static uint8_t *ppp_conf_nak(sessionidt s
, uint8_t *buf
, size_t blen
, uint16_t mtype
,
440 uint8_t **response
, uint8_t *queued
, uint8_t *packet
, uint8_t *option
,
441 uint8_t *value
, size_t vlen
)
446 case PPPLCP
: nak_sent
= &sess_local
[s
].lcp
.nak_sent
; break;
447 case PPPIPCP
: nak_sent
= &sess_local
[s
].ipcp
.nak_sent
; break;
448 case PPPIPV6CP
: nak_sent
= &sess_local
[s
].ipv6cp
.nak_sent
; break;
449 default: return 0; // ?
452 if (*response
&& **response
!= ConfigNak
)
454 if (*nak_sent
< config
->ppp_max_failure
) // reject queued
457 return ppp_conf_rej(s
, buf
, blen
, mtype
, response
, 0, packet
, option
);
462 if (*nak_sent
>= config
->ppp_max_failure
)
463 return ppp_conf_rej(s
, buf
, blen
, mtype
, response
, 0, packet
, option
);
465 queued
= *response
= makeppp(buf
, blen
, packet
, 2, s
, session
[s
].tunnel
, mtype
, 0, 0, 0);
474 if ((queued
- buf
+ vlen
+ 2) > blen
)
476 LOG(2, s
, session
[s
].tunnel
, "PPP overflow for ConfigNak (proto %u, option %u).\n", mtype
, *option
);
481 *queued
++ = vlen
+ 2;
482 memcpy(queued
, value
, vlen
);
483 return queued
+ vlen
;
486 static void ppp_code_rej(sessionidt s
, tunnelidt t
, uint16_t proto
,
487 char *pname
, uint8_t *p
, uint16_t l
, uint8_t *buf
, size_t size
)
490 int mru
= session
[s
].mru
;
491 if (mru
< MINMTU
) mru
= MINMTU
;
492 if (mru
> size
) mru
= size
;
495 if (l
> mru
) l
= mru
;
497 q
= makeppp(buf
, size
, 0, 0, s
, t
, proto
, 0, 0, 0);
501 *(q
+ 1) = ++sess_local
[s
].lcp_ident
;
502 *(uint16_t *)(q
+ 2) = htons(l
);
503 memcpy(q
+ 4, p
, l
- 4);
505 LOG(2, s
, t
, "Unexpected %s code %s\n", pname
, ppp_code(*p
));
506 LOG(3, s
, t
, "%s: send %s\n", pname
, ppp_code(*q
));
507 if (config
->debug
> 3) dumplcp(q
, l
);
509 tunnelsend(buf
, l
+ (q
- buf
), t
);
512 // Process LCP messages
513 void processlcp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
521 LOG_HEX(5, "LCP", p
, l
);
524 LOG(1, s
, t
, "Short LCP %d bytes\n", l
);
525 STAT(tunnel_rx_errors
);
529 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
531 LOG(1, s
, t
, "Length mismatch LCP %u/%u\n", hl
, l
);
532 STAT(tunnel_rx_errors
);
537 if (session
[s
].die
) // going down...
540 LOG((*p
== EchoReq
|| *p
== EchoReply
) ? 4 : 3, s
, t
,
541 "LCP: recv %s\n", ppp_code(*p
));
543 if (config
->debug
> 3) dumplcp(p
, l
);
548 uint8_t *o
= (p
+ 4);
556 if (length
== 0 || type
== 0 || x
< length
) break;
559 case 3: // Authentication-Protocol
561 int proto
= ntohs(*(uint16_t *)(o
+ 2));
564 else if (proto
== PPPCHAP
&& *(o
+ 4) == 5)
574 if (!session
[s
].ip
&& authtype
)
575 sess_local
[s
].lcp_authtype
= authtype
;
577 switch (session
[s
].ppp
.lcp
)
580 initialise_restart_count(s
, lcp
);
581 change_state(s
, lcp
, AckReceived
);
586 LOG(2, s
, t
, "LCP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.lcp
));
587 if (session
[s
].ppp
.lcp
== Opened
)
591 change_state(s
, lcp
, RequestSent
);
599 LOG(2, s
, t
, "LCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.lcp
));
602 else if (*p
== ConfigReq
)
605 uint8_t *o
= (p
+ 4);
606 uint8_t *response
= 0;
607 static uint8_t asyncmap
[4] = { 0, 0, 0, 0 }; // all zero
608 static uint8_t authproto
[5];
616 if (length
== 0 || type
== 0 || x
< length
) break;
619 case 1: // Maximum-Receive-Unit
621 uint16_t mru
= ntohs(*(uint16_t *)(o
+ 2));
624 session
[s
].mru
= mru
;
629 LOG(3, s
, t
, " Remote requesting MRU of %u. Rejecting.\n", mru
);
631 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
, (uint8_t *) &mru
, sizeof(mru
));
635 case 2: // Async-Control-Character-Map
636 if (!ntohl(*(uint32_t *)(o
+ 2))) // all bits zero is OK
639 LOG(3, s
, t
, " Remote requesting asyncmap. Rejecting.\n");
640 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
, asyncmap
, sizeof(asyncmap
));
643 case 3: // Authentication-Protocol
645 int proto
= ntohs(*(uint16_t *)(o
+ 2));
646 char proto_name
[] = "0x0000";
651 if (config
->radius_authtypes
& AUTHPAP
)
653 sess_local
[s
].lcp_authtype
= AUTHPAP
;
657 strcpy(proto_name
, "PAP");
659 else if (proto
== PPPCHAP
)
661 if (config
->radius_authtypes
& AUTHCHAP
662 && *(o
+ 4) == 5) // MD5
664 sess_local
[s
].lcp_authtype
= AUTHCHAP
;
668 strcpy(proto_name
, "CHAP");
671 sprintf(proto_name
, "%#4.4x", proto
);
673 LOG(3, s
, t
, " Remote requesting %s authentication. Rejecting.\n", proto_name
);
675 alen
= add_lcp_auth(authproto
, sizeof(authproto
), config
->radius_authprefer
);
676 if (alen
< 2) break; // paranoia
678 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
, authproto
+ 2, alen
- 2);
679 if (q
&& *response
== ConfigNak
&&
680 config
->radius_authtypes
!= config
->radius_authprefer
)
683 alen
= add_lcp_auth(authproto
, sizeof(authproto
), config
->radius_authtypes
& ~config
->radius_authprefer
);
685 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
, authproto
+ 2, alen
- 2);
692 case 4: // Quality-Protocol
693 case 5: // Magic-Number
694 case 7: // Protocol-Field-Compression
695 case 8: // Address-And-Control-Field-Compression
698 case 17: // Multilink Max-Receive-Reconstructed-Unit
700 uint16_t mrru
= ntohs(*(uint16_t *)(o
+ 2));
701 session
[s
].mrru
= mrru
;
703 LOG(3, s
, t
, " Received PPP LCP option MRRU: %d\n",mrru
);
707 case 18: // Multilink Short Sequence Number Header Format
711 LOG(3, s
, t
, " Received PPP LCP option MSSN format\n");
715 case 19: // Multilink Endpoint Discriminator
717 uint8_t epdis_class
= o
[2];
720 session
[s
].epdis
.addr_class
= epdis_class
;
721 session
[s
].epdis
.length
= length
- 3;
722 if (session
[s
].epdis
.length
> 20)
724 LOG(1, s
, t
, "Error: received EndDis Address Length more than 20: %d\n", session
[s
].epdis
.length
);
725 session
[s
].epdis
.length
= 20;
728 for (addr
= 0; addr
< session
[s
].epdis
.length
; addr
++)
729 session
[s
].epdis
.address
[addr
] = o
[3+addr
];
736 LOG(3, s
, t
, " Received PPP LCP option Multilink EndDis Local Address Class: %d\n",epdis_class
);
739 LOG(3, s
, t
, " Received PPP LCP option Multilink EndDis IP Address Class: %d\n",epdis_class
);
742 LOG(3, s
, t
, " Received PPP LCP option Multilink EndDis IEEE MAC Address Class: %d\n",epdis_class
);
745 LOG(3, s
, t
, " Received PPP LCP option Multilink EndDis PPP Magic No Class: %d\n",epdis_class
);
748 LOG(3, s
, t
, " Received PPP LCP option Multilink EndDis PSND No Class: %d\n",epdis_class
);
751 LOG(3, s
, t
, " Received PPP LCP option Multilink EndDis NULL Class %d\n",epdis_class
);
756 default: // Reject any unknown options
757 LOG(3, s
, t
, " Rejecting unknown PPP LCP option %d\n", type
);
758 q
= ppp_conf_rej(s
, b
, sizeof(b
), PPPLCP
, &response
, q
, p
, o
);
765 cluster_send_session(s
);
769 l
= q
- response
; // LCP packet length
770 *((uint16_t *) (response
+ 2)) = htons(l
); // update header
774 // Send packet back as ConfigAck
775 response
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPLCP
, 0, 0, 0);
776 if (!response
) return;
777 *response
= ConfigAck
;
780 switch (session
[s
].ppp
.lcp
)
783 response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPLCP
, 0, 0, 0);
784 if (!response
) return;
785 *response
= TerminateAck
;
786 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
790 initialise_restart_count(s
, lcp
);
792 if (*response
== ConfigAck
)
793 change_state(s
, lcp
, AckSent
);
795 change_state(s
, lcp
, RequestSent
);
800 if (*response
== ConfigAck
)
801 change_state(s
, lcp
, AckSent
);
806 if (*response
== ConfigAck
)
817 if (*response
== ConfigAck
)
818 change_state(s
, lcp
, AckSent
);
820 change_state(s
, lcp
, RequestSent
);
825 sessionshutdown(s
, "LCP: ConfigReq in state Closing. This should not happen. Killing session.", CDN_ADMIN_DISC
, TERM_LOST_SERVICE
);
829 LOG(2, s
, t
, "LCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.lcp
));
833 LOG(3, s
, t
, "LCP: send %s\n", ppp_code(*response
));
834 if (config
->debug
> 3) dumplcp(response
, l
);
836 tunnelsend(b
, l
+ (response
- b
), t
);
838 else if (*p
== ConfigNak
|| *p
== ConfigRej
)
841 uint8_t *o
= (p
+ 4);
849 if (length
== 0 || type
== 0 || x
< length
) break;
852 case 1: // Maximum-Receive-Unit
855 if (length
< 4) break;
856 sess_local
[s
].ppp_mru
= ntohs(*(uint16_t *)(o
+ 2));
857 LOG(3, s
, t
, " Remote requested MRU of %u\n", sess_local
[s
].ppp_mru
);
861 sess_local
[s
].ppp_mru
= 0;
862 LOG(3, s
, t
, " Remote rejected MRU negotiation\n");
867 case 3: // Authentication-Protocol
875 if (length
< 4) break;
876 proto
= ntohs(*(uint16_t *)(o
+ 2));
880 authtype
= config
->radius_authtypes
& AUTHPAP
;
881 LOG(3, s
, t
, " Remote requested PAP authentication...%sing\n",
882 authtype
? "accept" : "reject");
884 else if (proto
== PPPCHAP
&& length
> 4 && *(o
+ 4) == 5)
886 authtype
= config
->radius_authtypes
& AUTHCHAP
;
887 LOG(3, s
, t
, " Remote requested CHAP authentication...%sing\n",
888 authtype
? "accept" : "reject");
892 LOG(3, s
, t
, " Rejecting unsupported authentication %#4x\n",
898 LOG(2, s
, t
, "LCP: remote rejected auth negotiation\n");
899 authtype
= 0; // shutdown
904 case 5: // Magic-Number
905 session
[s
].magic
= 0;
908 if (length
< 6) break;
909 session
[s
].magic
= ntohl(*(uint32_t *)(o
+ 2));
912 if (session
[s
].magic
)
913 LOG(3, s
, t
, " Remote requested magic-no %x\n", session
[s
].magic
);
915 LOG(3, s
, t
, " Remote rejected magic-no\n");
917 cluster_send_session(s
);
920 case 17: // Multilink Max-Receive-Reconstructed-Unit
924 sess_local
[s
].mp_mrru
= ntohs(*(uint16_t *)(o
+ 2));
925 LOG(3, s
, t
, " Remote requested MRRU of %u\n", sess_local
[s
].mp_mrru
);
929 sess_local
[s
].mp_mrru
= 0;
930 LOG(3, s
, t
, " Remote rejected MRRU negotiation\n");
935 case 18: // Multilink Short Sequence Number Header Format
939 sess_local
[s
].mp_mssf
= 0;
940 LOG(3, s
, t
, " Remote requested Naked mssf\n");
944 sess_local
[s
].mp_mssf
= 0;
945 LOG(3, s
, t
, " Remote rejected mssf\n");
950 case 19: // Multilink Endpoint Discriminator
954 LOG(2, s
, t
, " Remote should not configNak Endpoint Dis!\n");
958 sess_local
[s
].mp_epdis
= 0;
959 LOG(3, s
, t
, " Remote rejected Endpoint Discriminator\n");
965 LOG(2, s
, t
, "LCP: remote sent %s for type %u?\n", ppp_code(*p
), type
);
966 sessionshutdown(s
, "Unable to negotiate LCP.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
975 sessionshutdown(s
, "Unsupported authentication.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
980 sess_local
[s
].lcp_authtype
= authtype
;
982 switch (session
[s
].ppp
.lcp
)
987 uint8_t *response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPLCP
, 0, 0, 0);
988 if (!response
) return;
989 *response
= TerminateAck
;
990 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
992 LOG(3, s
, t
, "LCP: send %s\n", ppp_code(*response
));
993 if (config
->debug
> 3) dumplcp(response
, l
);
995 tunnelsend(b
, l
+ (response
- b
), t
);
1001 initialise_restart_count(s
, lcp
);
1006 LOG(2, s
, t
, "LCP: ConfigNak in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.lcp
));
1016 LOG(2, s
, t
, "LCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.lcp
));
1020 else if (*p
== TerminateReq
)
1022 switch (session
[s
].ppp
.lcp
)
1035 zero_restart_count(s
, lcp
);
1036 change_state(s
, lcp
, Closing
);
1040 LOG(2, s
, t
, "LCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.lcp
));
1044 *p
= TerminateAck
; // send ack
1045 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPLCP
, 0, 0, 0);
1048 LOG(3, s
, t
, "LCP: send %s\n", ppp_code(*q
));
1049 if (config
->debug
> 3) dumplcp(q
, l
);
1051 tunnelsend(b
, l
+ (q
- b
), t
); // send it
1053 else if (*p
== ProtocolRej
)
1060 if (l
> 5 && !(proto
& 1))
1067 if (proto
== PPPIPV6CP
)
1069 LOG(3, s
, t
, "IPv6 rejected\n");
1070 change_state(s
, ipv6cp
, Closed
);
1074 LOG(3, s
, t
, "LCP protocol reject: 0x%04X\n", proto
);
1077 else if (*p
== EchoReq
)
1079 *p
= EchoReply
; // reply
1080 *(uint32_t *) (p
+ 4) = htonl(session
[s
].magic
); // our magic number
1081 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPLCP
, 0, 0, 0);
1084 LOG(4, s
, t
, "LCP: send %s\n", ppp_code(*q
));
1085 if (config
->debug
> 3) dumplcp(q
, l
);
1087 tunnelsend(b
, l
+ (q
- b
), t
); // send it
1089 else if (*p
== EchoReply
)
1091 // Ignore it, last_packet time is set earlier than this.
1093 else if (*p
!= CodeRej
)
1095 ppp_code_rej(s
, t
, PPPLCP
, "LCP", p
, l
, b
, sizeof(b
));
1099 int join_bundle(sessionidt s
)
1101 // Search for a bundle to join
1104 for (i
= 1; i
< MAXBUNDLE
; i
++)
1106 if (bundle
[i
].state
!= BUNDLEFREE
)
1108 if (epdiscmp(session
[s
].epdis
,bundle
[i
].epdis
) && !strcmp(session
[s
].user
, bundle
[i
].user
))
1110 sessionidt first_ses
= bundle
[i
].members
[0];
1111 if (bundle
[i
].mssf
!= session
[s
].mssf
)
1113 // uniformity of sequence number format must be insured
1114 LOG(3, s
, session
[s
].tunnel
, "MPPP: unable to bundle session %d in bundle %d cause of different mssf\n", s
, i
);
1117 session
[s
].bundle
= i
;
1118 session
[s
].ip
= session
[first_ses
].ip
;
1119 session
[s
].dns1
= session
[first_ses
].dns1
;
1120 session
[s
].dns2
= session
[first_ses
].dns2
;
1121 session
[s
].timeout
= session
[first_ses
].timeout
;
1123 if(session
[s
].epdis
.length
> 0)
1124 setepdis(&bundle
[i
].epdis
, session
[s
].epdis
);
1126 strcpy(bundle
[i
].user
, session
[s
].user
);
1127 bundle
[i
].members
[bundle
[i
].num_of_links
] = s
;
1128 bundle
[i
].num_of_links
++;
1129 LOG(3, s
, session
[s
].tunnel
, "MPPP: Bundling additional line in bundle (%d), lines:%d\n",i
,bundle
[i
].num_of_links
);
1135 // No previously created bundle was found for this session, so create a new one
1136 if (!(b
= new_bundle())) return 0;
1138 session
[s
].bundle
= b
;
1139 bundle
[b
].mrru
= session
[s
].mrru
;
1140 bundle
[b
].mssf
= session
[s
].mssf
;
1141 // FIXME !!! to enable l2tpns reading mssf frames receiver_max_seq, sender_max_seq must be introduce
1142 // now session[s].mssf flag indecates that the receiver wish to receive frames in mssf, so max_seq (i.e. recv_max_seq) = 1<<24
1145 bundle[b].max_seq = 1 << 12;
1147 bundle
[b
].max_seq
= 1 << 24;
1148 if(session
[s
].epdis
.length
> 0)
1149 setepdis(&bundle
[b
].epdis
, session
[s
].epdis
);
1151 strcpy(bundle
[b
].user
, session
[s
].user
);
1152 bundle
[b
].members
[0] = s
;
1153 bundle
[b
].timeout
= session
[s
].timeout
;
1154 LOG(3, s
, session
[s
].tunnel
, "MPPP: Created a new bundle (%d)\n", b
);
1158 static int epdiscmp(epdist ep1
, epdist ep2
)
1161 if (ep1
.length
!= ep2
.length
)
1164 if (ep1
.addr_class
!= ep2
.addr_class
)
1167 for (ad
= 0; ad
< ep1
.length
; ad
++)
1168 if (ep1
.address
[ad
] != ep2
.address
[ad
])
1174 static void setepdis(epdist
*ep1
, epdist ep2
)
1177 ep1
->length
= ep2
.length
;
1178 ep1
->addr_class
= ep2
.addr_class
;
1179 for (ad
= 0; ad
< ep2
.length
; ad
++)
1180 ep1
->address
[ad
] = ep2
.address
[ad
];
1183 static bundleidt
new_bundle()
1186 for (i
= 1; i
< MAXBUNDLE
; i
++)
1188 if (bundle
[i
].state
== BUNDLEFREE
)
1190 LOG(4, 0, 0, "MPPP: Assigning bundle ID %d\n", i
);
1191 bundle
[i
].num_of_links
= 1;
1192 bundle
[i
].last_check
= time_now
; // Initialize last_check value
1193 bundle
[i
].state
= BUNDLEOPEN
;
1194 bundle
[i
].current_ses
= -1; // This is to enforce the first session 0 to be used at first
1195 memset(&frag
[i
], 0, sizeof(fragmentationt
));
1196 if (i
> config
->cluster_highest_bundleid
)
1197 config
->cluster_highest_bundleid
= i
;
1201 LOG(0, 0, 0, "MPPP: Can't find a free bundle! There shouldn't be this many in use!\n");
1205 static void ipcp_open(sessionidt s
, tunnelidt t
)
1207 LOG(3, s
, t
, "IPCP: Opened, session is now active\n");
1209 change_state(s
, ipcp
, Opened
);
1211 if (!(session
[s
].walled_garden
|| session
[s
].flags
& SESSION_STARTED
))
1213 uint16_t r
= radiusnew(s
);
1216 radiussend(r
, RADIUSSTART
); // send radius start
1218 // don't send further Start records if IPCP is restarted
1219 session
[s
].flags
|= SESSION_STARTED
;
1220 cluster_send_session(s
);
1224 // start IPv6 if configured and still in passive state
1225 if (session
[s
].ppp
.ipv6cp
== Stopped
)
1228 change_state(s
, ipv6cp
, RequestSent
);
1232 // Process IPCP messages
1233 void processipcp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1235 uint8_t b
[MAXETHER
];
1241 LOG_HEX(5, "IPCP", p
, l
);
1244 LOG(1, s
, t
, "Short IPCP %d bytes\n", l
);
1245 STAT(tunnel_rx_errors
);
1249 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
1251 LOG(1, s
, t
, "Length mismatch IPCP %u/%u\n", hl
, l
);
1252 STAT(tunnel_rx_errors
);
1257 if (session
[s
].ppp
.phase
< Network
)
1259 LOG(2, s
, t
, "IPCP %s ignored in %s phase\n", ppp_code(*p
), ppp_phase(session
[s
].ppp
.phase
));
1263 LOG(3, s
, t
, "IPCP: recv %s\n", ppp_code(*p
));
1265 if (*p
== ConfigAck
)
1267 switch (session
[s
].ppp
.ipcp
)
1270 initialise_restart_count(s
, ipcp
);
1271 change_state(s
, ipcp
, AckReceived
);
1276 LOG(2, s
, t
, "IPCP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.ipcp
));
1278 change_state(s
, ipcp
, RequestSent
);
1286 LOG(2, s
, t
, "IPCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipcp
));
1289 else if (*p
== ConfigReq
)
1291 uint8_t *response
= 0;
1299 if (!o
[1] || o
[1] > length
) return;
1303 case 3: // ip address
1304 gotip
++; // seen address
1305 if (o
[1] != 6) return;
1307 addr
= htonl(session
[s
].ip
);
1308 if (memcmp(o
+ 2, &addr
, (sizeof addr
)))
1311 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
, (uint8_t *) &addr
, sizeof(addr
));
1312 if (!q
|| (q
!= oq
&& *response
== ConfigRej
))
1314 sessionshutdown(s
, "Can't negotiate IPCP.", CDN_ADMIN_DISC
, TERM_USER_ERROR
);
1321 case 129: // primary DNS
1322 if (o
[1] != 6) return;
1324 addr
= htonl(session
[s
].dns1
);
1325 if (memcmp(o
+ 2, &addr
, (sizeof addr
)))
1327 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
, (uint8_t *) &addr
, sizeof(addr
));
1333 case 131: // secondary DNS
1334 if (o
[1] != 6) return;
1336 addr
= htonl(session
[s
].dns2
);
1337 if (memcmp(o
+ 2, &addr
, sizeof(addr
)))
1339 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
, (uint8_t *) &addr
, sizeof(addr
));
1346 LOG(2, s
, t
, " Rejecting PPP IPCP Option type %d\n", *o
);
1347 q
= ppp_conf_rej(s
, b
, sizeof(b
), PPPIPCP
, &response
, q
, p
, o
);
1357 l
= q
- response
; // IPCP packet length
1358 *((uint16_t *) (response
+ 2)) = htons(l
); // update header
1362 // Send packet back as ConfigAck
1363 response
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPCP
, 0, 0, 0);
1364 if (!response
) return;
1365 *response
= ConfigAck
;
1369 LOG(1, s
, t
, "No IP in IPCP request\n");
1370 STAT(tunnel_rx_errors
);
1374 switch (session
[s
].ppp
.ipcp
)
1377 response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPIPCP
, 0, 0, 0);
1378 if (!response
) return;
1379 *response
= TerminateAck
;
1380 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
1384 initialise_restart_count(s
, ipcp
);
1386 if (*response
== ConfigAck
)
1387 change_state(s
, ipcp
, AckSent
);
1389 change_state(s
, ipcp
, RequestSent
);
1394 if (*response
== ConfigAck
)
1395 change_state(s
, ipcp
, AckSent
);
1400 if (*response
== ConfigAck
)
1406 initialise_restart_count(s
, ipcp
);
1411 if (*response
== ConfigAck
)
1412 change_state(s
, ipcp
, AckSent
);
1414 change_state(s
, ipcp
, RequestSent
);
1419 LOG(2, s
, t
, "IPCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipcp
));
1423 LOG(3, s
, t
, "IPCP: send %s\n", ppp_code(*response
));
1424 tunnelsend(b
, l
+ (response
- b
), t
);
1426 else if (*p
== TerminateReq
)
1428 switch (session
[s
].ppp
.ipcp
)
1440 zero_restart_count(s
, ipcp
);
1441 change_state(s
, ipcp
, Closing
);
1445 LOG(2, s
, t
, "IPCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipcp
));
1449 *p
= TerminateAck
; // send ack
1450 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPCP
, 0, 0, 0);
1453 LOG(3, s
, t
, "IPCP: send %s\n", ppp_code(*q
));
1454 tunnelsend(b
, l
+ (q
- b
), t
); // send it
1456 else if (*p
!= CodeRej
)
1458 ppp_code_rej(s
, t
, PPPIPCP
, "IPCP", p
, l
, b
, sizeof(b
));
1462 static void ipv6cp_open(sessionidt s
, tunnelidt t
)
1464 LOG(3, s
, t
, "IPV6CP: Opened\n");
1466 change_state(s
, ipv6cp
, Opened
);
1467 if (session
[s
].ipv6prefixlen
)
1468 route6set(s
, session
[s
].ipv6route
, session
[s
].ipv6prefixlen
, 1);
1470 // Send an initial RA (TODO: Should we send these regularly?)
1471 send_ipv6_ra(s
, t
, NULL
);
1474 // Process IPV6CP messages
1475 void processipv6cp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1477 uint8_t b
[MAXETHER
];
1481 CSTAT(processipv6cp
);
1483 LOG_HEX(5, "IPV6CP", p
, l
);
1486 LOG(1, s
, t
, "Short IPV6CP %d bytes\n", l
);
1487 STAT(tunnel_rx_errors
);
1491 if ((hl
= ntohs(*(uint16_t *) (p
+ 2))) > l
)
1493 LOG(1, s
, t
, "Length mismatch IPV6CP %u/%u\n", hl
, l
);
1494 STAT(tunnel_rx_errors
);
1499 if (session
[s
].ppp
.phase
< Network
)
1501 LOG(2, s
, t
, "IPV6CP %s ignored in %s phase\n", ppp_code(*p
), ppp_phase(session
[s
].ppp
.phase
));
1505 LOG(3, s
, t
, "IPV6CP: recv %s\n", ppp_code(*p
));
1509 LOG(3, s
, t
, "IPV6CP: no IPv4 address (IPCP in state %s)\n", ppp_state(session
[s
].ppp
.ipcp
));
1510 return; // need IPCP to complete...
1513 if (*p
== ConfigAck
)
1515 switch (session
[s
].ppp
.ipv6cp
)
1518 initialise_restart_count(s
, ipv6cp
);
1519 change_state(s
, ipv6cp
, AckReceived
);
1524 LOG(2, s
, t
, "IPV6CP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.ipv6cp
));
1526 change_state(s
, ipv6cp
, RequestSent
);
1534 LOG(2, s
, t
, "IPV6CP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipv6cp
));
1537 else if (*p
== ConfigReq
)
1539 uint8_t *response
= 0;
1547 if (!o
[1] || o
[1] > length
) return;
1551 case 1: // interface identifier
1552 gotip
++; // seen address
1553 if (o
[1] != 10) return;
1555 ident
[0] = htonl(session
[s
].ip
);
1558 if (memcmp(o
+ 2, ident
, sizeof(ident
)))
1560 q
= ppp_conf_nak(s
, b
, sizeof(b
), PPPIPV6CP
, &response
, q
, p
, o
, (uint8_t *)ident
, sizeof(ident
));
1567 LOG(2, s
, t
, " Rejecting PPP IPV6CP Option type %d\n", *o
);
1568 q
= ppp_conf_rej(s
, b
, sizeof(b
), PPPIPV6CP
, &response
, q
, p
, o
);
1578 l
= q
- response
; // IPV6CP packet length
1579 *((uint16_t *) (response
+ 2)) = htons(l
); // update header
1583 // Send packet back as ConfigAck
1584 response
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPV6CP
, 0, 0, 0);
1585 if (!response
) return;
1586 *response
= ConfigAck
;
1590 LOG(1, s
, t
, "No interface identifier in IPV6CP request\n");
1591 STAT(tunnel_rx_errors
);
1595 switch (session
[s
].ppp
.ipv6cp
)
1598 response
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPIPV6CP
, 0, 0, 0);
1599 if (!response
) return;
1600 *response
= TerminateAck
;
1601 *((uint16_t *) (response
+ 2)) = htons(l
= 4);
1605 initialise_restart_count(s
, ipv6cp
);
1607 if (*response
== ConfigAck
)
1608 change_state(s
, ipv6cp
, AckSent
);
1610 change_state(s
, ipv6cp
, RequestSent
);
1615 if (*response
== ConfigAck
)
1616 change_state(s
, ipv6cp
, AckSent
);
1621 if (*response
== ConfigAck
)
1627 initialise_restart_count(s
, ipv6cp
);
1632 if (*response
== ConfigAck
)
1633 change_state(s
, ipv6cp
, AckSent
);
1635 change_state(s
, ipv6cp
, RequestSent
);
1640 LOG(2, s
, t
, "IPV6CP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipv6cp
));
1644 LOG(3, s
, t
, "IPV6CP: send %s\n", ppp_code(*response
));
1645 tunnelsend(b
, l
+ (response
- b
), t
);
1647 else if (*p
== TerminateReq
)
1649 switch (session
[s
].ppp
.ipv6cp
)
1661 zero_restart_count(s
, ipv6cp
);
1662 change_state(s
, ipv6cp
, Closing
);
1666 LOG(2, s
, t
, "IPV6CP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ipv6cp
));
1670 *p
= TerminateAck
; // send ack
1671 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPIPV6CP
, 0, 0, 0);
1674 LOG(3, s
, t
, "IPV6CP: send %s\n", ppp_code(*q
));
1675 tunnelsend(b
, l
+ (q
- b
), t
); // send it
1677 else if (*p
!= CodeRej
)
1679 ppp_code_rej(s
, t
, PPPIPV6CP
, "IPV6CP", p
, l
, b
, sizeof(b
));
1683 static void update_sessions_in_stat(sessionidt s
, uint16_t l
)
1685 bundleidt b
= session
[s
].bundle
;
1688 increment_counter(&session
[s
].cin
, &session
[s
].cin_wrap
, l
);
1689 session
[s
].cin_delta
+= l
;
1692 sess_local
[s
].cin
+= l
;
1693 sess_local
[s
].pin
++;
1697 int i
= frag
[b
].re_frame_begin_index
;
1698 int end
= frag
[b
].re_frame_end_index
;
1701 l
= frag
[b
].fragment
[i
].length
;
1702 s
= frag
[b
].fragment
[i
].sid
;
1703 increment_counter(&session
[s
].cin
, &session
[s
].cin_wrap
, l
);
1704 session
[s
].cin_delta
+= l
;
1707 sess_local
[s
].cin
+= l
;
1708 sess_local
[s
].pin
++;
1711 i
= (i
+ 1) & MAXFRAGNUM_MASK
;
1716 // process IP packet received
1718 // This MUST be called with at least 4 byte behind 'p'.
1719 // (i.e. this routine writes to p[-4]).
1720 void processipin(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1726 LOG_HEX(5, "IP", p
, l
);
1730 LOG(1, s
, t
, "IP packet too short %d\n", l
);
1731 STAT(tunnel_rx_errors
);
1735 ip
= ntohl(*(uint32_t *)(p
+ 12));
1739 LOG(1, s
, t
, "IP packet too long %d\n", l
);
1740 STAT(tunnel_rx_errors
);
1744 if (session
[s
].ppp
.phase
!= Network
|| session
[s
].ppp
.ipcp
!= Opened
)
1747 if (!session
[s
].bundle
|| bundle
[session
[s
].bundle
].num_of_links
< 2) // FIXME:
1749 // no spoof (do sessionbyip to handled statically routed subnets)
1750 if (ip
!= session
[s
].ip
&& sessionbyip(htonl(ip
)) != s
)
1752 LOG(4, s
, t
, "Dropping packet with spoofed IP %s\n", fmtaddr(htonl(ip
), 0));
1757 // run access-list if any
1758 if (session
[s
].filter_in
&& !ip_filter(p
, l
, session
[s
].filter_in
- 1))
1761 // adjust MSS on SYN and SYN,ACK packets with options
1762 if ((ntohs(*(uint16_t *) (p
+ 6)) & 0x1fff) == 0 && p
[9] == IPPROTO_TCP
) // first tcp fragment
1764 int ihl
= (p
[0] & 0xf) * 4; // length of IP header
1765 if (l
>= ihl
+ 20 && (p
[ihl
+ 13] & TCP_FLAG_SYN
) && ((p
[ihl
+ 12] >> 4) > 5))
1766 adjust_tcp_mss(s
, t
, p
, l
, p
+ ihl
);
1769 // Add on the tun header
1771 *(uint32_t *) p
= htonl(PKTIP
);
1774 if (session
[s
].tbf_in
)
1776 // Are we throttling this session?
1777 if (config
->cluster_iam_master
)
1778 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
1780 master_throttle_packet(session
[s
].tbf_in
, p
, l
);
1785 if (tun_write(p
, l
) < 0)
1787 STAT(tun_tx_errors
);
1788 LOG(0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
1789 l
, strerror(errno
), tunfd
, p
);
1797 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
1799 // Snooping this session
1800 snoop_send_packet(p
, l
, session
[s
].snoop_ip
, session
[s
].snoop_port
);
1803 update_sessions_in_stat(s
, l
);
1807 STAT(tun_tx_packets
);
1808 INC_STAT(tun_tx_bytes
, l
);
1811 // process Multilink PPP packet received
1812 void processmpin(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
1814 bundleidt b
= session
[s
].bundle
;
1815 bundlet
* this_bundle
= &bundle
[b
];
1816 uint32_t frag_offset
, M_offset
;
1817 uint16_t frag_index
, M_index
;
1818 fragmentationt
*this_fragmentation
= &frag
[b
];
1819 uint8_t begin_frame
= (*p
& MP_BEGIN
);
1820 uint8_t end_frame
= (*p
& MP_END
);
1823 uint16_t begin_index
, end_index
;
1825 // Perform length checking
1828 LOG(2, s
, t
, "MPPP: discarding fragment larger than MAXFRAGLEN\n");
1834 LOG(2, s
, t
, "MPPP: Invalid bundle id: 0\n");
1837 // FIXME !! session[s].mssf means that the receiver wants to receive frames in mssf not means the receiver will send frames in mssf
1838 /* if(session[s].mssf)
1840 // Get 12 bit for seq number
1841 seq_num = ntohs((*(uint16_t *) p) & 0xFF0F);
1844 // After this point the pointer should be advanced 2 bytes
1845 LOG(3, s, t, "MPPP: 12 bits, sequence number: %d\n",seq_num);
1849 // Get 24 bit for seq number
1850 seq_num
= ntohl((*(uint32_t *) p
) & 0xFFFFFF00);
1853 // After this point the pointer should be advanced 4 bytes
1854 LOG(4, s
, t
, "MPPP: 24 bits sequence number:%d\n",seq_num
);
1857 // calculate this fragment's offset from the begin seq in the bundle
1858 frag_offset
= (seq_num
+ this_bundle
->max_seq
- this_fragmentation
->start_seq
) & (this_bundle
->max_seq
-1);
1860 // discard this fragment if frag_offset is bigger that the fragmentation buffer size
1861 if (frag_offset
>= MAXFRAGNUM
)
1863 LOG(3, s
, t
, "MPPP: Index out of range, received more than MAXFRAGNUM fragment (lost frag) seq:%d, begin_seq:%d, bundle:%d, max:%d\n",seq_num
, this_fragmentation
->start_seq
, b
, this_bundle
->max_seq
);
1868 sess_local
[s
].last_seq
= seq_num
;
1869 if (seq_num
< this_fragmentation
->M
)
1870 this_fragmentation
->M
= seq_num
;
1873 uint32_t i
, min
= sess_local
[(this_bundle
->members
[0])].last_seq
;;
1874 for (i
= 1; i
< this_bundle
->num_of_links
; i
++)
1876 uint32_t s_seq
= sess_local
[(this_bundle
->members
[i
])].last_seq
;
1880 this_fragmentation
->M
= min
;
1883 LOG(4, s
, t
, "MPPP: Setting M to %d\n", this_fragmentation
->M
);
1884 //calculate M's offset from the begin seq in the bundle
1885 M_offset
= (this_fragmentation
->M
+ this_bundle
->max_seq
- this_fragmentation
->start_seq
) & (this_bundle
->max_seq
-1);
1887 //caculate M's index in the fragment array
1888 M_index
= (M_offset
+ this_fragmentation
->start_index
) & MAXFRAGNUM_MASK
;
1890 //caculate received fragment's index in the fragment array
1891 frag_index
= (frag_offset
+ this_fragmentation
->start_index
) & MAXFRAGNUM_MASK
;
1893 //frame with a single fragment
1894 if (begin_frame
&& end_frame
)
1896 // process and reset fragmentation
1897 LOG(4, s
, t
, "MPPP: Both bits are set (Begin and End).\n");
1898 this_fragmentation
->fragment
[frag_index
].length
= l
;
1899 this_fragmentation
->fragment
[frag_index
].sid
= s
;
1900 this_fragmentation
->fragment
[frag_index
].flags
= flags
;
1901 this_fragmentation
->fragment
[frag_index
].seq
= seq_num
;
1902 this_fragmentation
->re_frame_begin_index
= frag_index
;
1903 this_fragmentation
->re_frame_end_index
= frag_index
;
1904 processmpframe(s
, t
, p
, l
, 0);
1905 this_fragmentation
->fragment
[frag_index
].length
= 0;
1906 this_fragmentation
->fragment
[frag_index
].flags
= 0;
1907 end_index
= frag_index
;
1911 // insert the frame in it's place
1912 fragmentt
*this_frag
= &this_fragmentation
->fragment
[frag_index
];
1913 this_frag
->length
= l
;
1915 this_frag
->flags
= flags
;
1916 this_frag
->seq
= seq_num
;
1917 memcpy(this_frag
->data
, p
, l
);
1919 // try to assemble the frame that has the received fragment as a member
1920 // get the beginning of this frame
1921 begin_index
= end_index
= frag_index
;
1922 while (this_fragmentation
->fragment
[begin_index
].length
)
1924 if (this_fragmentation
->fragment
[begin_index
].flags
& MP_BEGIN
)
1926 begin_index
= (begin_index
? (begin_index
-1) : (MAXFRAGNUM
-1));
1929 // return if a lost fragment is found
1930 if (!(this_fragmentation
->fragment
[begin_index
].length
))
1931 return; // assembling frame failed
1932 // get the end of his frame
1933 while (this_fragmentation
->fragment
[end_index
].length
)
1935 if (this_fragmentation
->fragment
[end_index
].flags
& MP_END
)
1937 end_index
= (end_index
+1) & MAXFRAGNUM_MASK
;
1940 // return if a lost fragment is found
1941 if (!(this_fragmentation
->fragment
[end_index
].length
))
1942 return; // assembling frame failed
1944 // assemble the packet
1945 //assemble frame, process it, reset fragmentation
1946 uint16_t cur_len
= 4; // This is set to 4 to leave 4 bytes for function processipin
1949 LOG(4, s
, t
, "MPPP: processing fragments from %d to %d\n", begin_index
, end_index
);
1950 // Push to the receive buffer
1952 for (i
= begin_index
;; i
= (i
+ 1) & MAXFRAGNUM_MASK
)
1954 this_frag
= &this_fragmentation
->fragment
[i
];
1955 if(cur_len
+ this_frag
->length
> MAXETHER
)
1957 LOG(2, s
, t
, "MPPP: discarding reassembled frames larger than MAXETHER\n");
1960 memcpy(this_fragmentation
->reassembled_frame
+cur_len
, this_frag
->data
, this_frag
->length
);
1961 LOG(5, s
, t
, "MPPP: processing frame at %d, with len %d\n", i
, this_frag
->length
);
1962 cur_len
+= this_frag
->length
;
1965 this_fragmentation
->re_frame_len
= cur_len
;
1966 this_fragmentation
->re_frame_begin_index
= begin_index
;
1967 this_fragmentation
->re_frame_end_index
= end_index
;
1968 // Process the resassembled frame
1969 LOG(5, s
, t
, "MPPP: Process the reassembled frame, len=%d\n",cur_len
);
1970 processmpframe(s
, t
, this_fragmentation
->reassembled_frame
, this_fragmentation
->re_frame_len
, 1);
1974 // Set reassembled frame length to zero after processing it
1975 this_fragmentation
->re_frame_len
= 0;
1976 for (i
= begin_index
;; i
= (i
+ 1) & MAXFRAGNUM_MASK
)
1978 this_fragmentation
->fragment
[i
].length
= 0; // Indicates that this fragment has been consumed
1979 this_fragmentation
->fragment
[i
].flags
= 0;
1984 //discard fragments received before the recently assembled frame
1985 begin_index
= this_fragmentation
->start_index
;
1986 this_fragmentation
->start_index
= (end_index
+ 1) & MAXFRAGNUM_MASK
;
1987 this_fragmentation
->start_seq
= (this_fragmentation
->fragment
[end_index
].seq
+ 1) & (this_bundle
->max_seq
-1);
1988 //clear length and flags of the discarded fragments
1989 while (begin_index
!= this_fragmentation
->start_index
)
1991 this_fragmentation
->fragment
[begin_index
].flags
= 0;
1992 this_fragmentation
->fragment
[begin_index
].length
= 0;
1993 begin_index
= (begin_index
+ 1) & MAXFRAGNUM_MASK
;
1996 LOG(4, s
, t
, "MPPP after assembling: M index is =%d, start index is = %d, start seq=%d\n",M_index
, this_fragmentation
->start_index
, this_fragmentation
->start_seq
);
2000 // process IPv6 packet received
2002 // This MUST be called with at least 4 byte behind 'p'.
2003 // (i.e. this routine writes to p[-4]).
2004 void processipv6in(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
2009 CSTAT(processipv6in
);
2011 LOG_HEX(5, "IPv6", p
, l
);
2013 ip
= *(struct in6_addr
*) (p
+ 8);
2014 ipv4
= ntohl(*(uint32_t *)(p
+ 16));
2018 LOG(1, s
, t
, "IP packet too long %d\n", l
);
2019 STAT(tunnel_rx_errors
);
2023 if (session
[s
].ppp
.phase
!= Network
|| session
[s
].ppp
.ipv6cp
!= Opened
)
2027 if (ipv4
!= session
[s
].ip
&& memcmp(&config
->ipv6_prefix
, &ip
, 8) && sessionbyipv6(ip
) != s
)
2029 char str
[INET6_ADDRSTRLEN
];
2030 LOG(5, s
, t
, "Dropping packet with spoofed IP %s\n",
2031 inet_ntop(AF_INET6
, &ip
, str
, INET6_ADDRSTRLEN
));
2035 // Check if it's a Router Solicition message.
2036 if (*(p
+ 6) == 58 && *(p
+ 7) == 255 && *(p
+ 24) == 0xFF && *(p
+ 25) == 2 &&
2037 *(uint32_t *)(p
+ 26) == 0 && *(uint32_t *)(p
+ 30) == 0 &&
2038 *(uint32_t *)(p
+ 34) == 0 &&
2039 *(p
+ 38) == 0 && *(p
+ 39) == 2 && *(p
+ 40) == 133) {
2040 LOG(3, s
, t
, "Got IPv6 RS\n");
2041 send_ipv6_ra(s
, t
, &ip
);
2045 // Add on the tun header
2047 *(uint32_t *) p
= htonl(PKTIPV6
);
2050 // Are we throttled and a slave?
2051 if (session
[s
].tbf_in
&& !config
->cluster_iam_master
) {
2052 // Pass it to the master for handling.
2053 master_throttle_packet(session
[s
].tbf_in
, p
, l
);
2057 // Are we throttled and a master??
2058 if (session
[s
].tbf_in
&& config
->cluster_iam_master
) {
2059 // Actually handle the throttled packets.
2060 tbf_queue_packet(session
[s
].tbf_in
, p
, l
);
2065 if (tun_write(p
, l
) < 0)
2067 STAT(tun_tx_errors
);
2068 LOG(0, s
, t
, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
2069 l
, strerror(errno
), tunfd
, p
);
2077 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
2079 // Snooping this session
2080 snoop_send_packet(p
, l
, session
[s
].snoop_ip
, session
[s
].snoop_port
);
2083 update_sessions_in_stat(s
, l
);
2087 STAT(tun_tx_packets
);
2088 INC_STAT(tun_tx_bytes
, l
);
2092 // Helper routine for the TBF filters.
2093 // Used to send queued data in from the user.
2095 void send_ipin(sessionidt s
, uint8_t *buf
, int len
)
2097 LOG_HEX(5, "IP in throttled", buf
, len
);
2099 if (write(tunfd
, buf
, len
) < 0)
2101 STAT(tun_tx_errors
);
2102 LOG(0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n",
2103 len
, strerror(errno
), tunfd
, buf
);
2111 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
2113 // Snooping this session
2114 snoop_send_packet(buf
, len
, session
[s
].snoop_ip
, session
[s
].snoop_port
);
2117 // Increment packet counters
2118 increment_counter(&session
[s
].cin
, &session
[s
].cin_wrap
, len
);
2119 session
[s
].cin_delta
+= len
;
2122 sess_local
[s
].cin
+= len
;
2123 sess_local
[s
].pin
++;
2127 STAT(tun_tx_packets
);
2128 INC_STAT(tun_tx_bytes
, len
- 4);
2132 // Process CCP messages
2133 void processccp(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
)
2135 uint8_t b
[MAXETHER
];
2140 LOG_HEX(5, "CCP", p
, l
);
2142 if (session
[s
].ppp
.phase
< Network
)
2144 LOG(2, s
, t
, "CCP %s ignored in %s phase\n", ppp_code(*p
), ppp_phase(session
[s
].ppp
.phase
));
2150 LOG(1, s
, t
, "Short CCP packet\n");
2151 STAT(tunnel_rx_errors
);
2154 LOG(4, s
, t
, "CCP: recv %s\n", ppp_code(*p
));
2155 if (*p
== ConfigAck
)
2157 switch (session
[s
].ppp
.ccp
)
2160 initialise_restart_count(s
, ccp
);
2161 change_state(s
, ccp
, AckReceived
);
2166 LOG(2, s
, t
, "CCP: ConfigAck in state %s? Sending ConfigReq\n", ppp_state(session
[s
].ppp
.ccp
));
2168 change_state(s
, ccp
, RequestSent
);
2172 LOG(3, s
, t
, "CCP: Opened\n");
2173 change_state(s
, ccp
, Opened
);
2177 LOG(2, s
, t
, "CCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ccp
));
2180 else if (*p
== ConfigReq
)
2182 if (l
< 6) // accept no compression
2184 else // compression requested--reject
2187 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPCCP
, 0, 0, 0);
2190 switch (session
[s
].ppp
.ccp
)
2193 q
= makeppp(b
, sizeof(b
), p
, 2, s
, t
, PPPCCP
, 0, 0, 0);
2196 *((uint16_t *) (q
+ 2)) = htons(l
= 4);
2200 initialise_restart_count(s
, ccp
);
2202 if (*q
== ConfigAck
)
2203 change_state(s
, ccp
, AckSent
);
2205 change_state(s
, ccp
, RequestSent
);
2210 if (*q
== ConfigAck
)
2211 change_state(s
, ccp
, AckSent
);
2216 if (*q
== ConfigAck
)
2217 change_state(s
, ccp
, Opened
);
2222 initialise_restart_count(s
, ccp
);
2227 if (*q
== ConfigAck
)
2228 change_state(s
, ccp
, AckSent
);
2230 change_state(s
, ccp
, RequestSent
);
2235 LOG(2, s
, t
, "CCP: ignoring %s in state %s\n", ppp_code(*p
), ppp_state(session
[s
].ppp
.ccp
));
2239 LOG(4, s
, t
, "CCP: send %s\n", ppp_code(*q
));
2240 tunnelsend(b
, l
+ (q
- b
), t
);
2242 else if (*p
== TerminateReq
)
2245 q
= makeppp(b
, sizeof(b
), p
, l
, s
, t
, PPPCCP
, 0, 0, 0);
2247 LOG(3, s
, t
, "CCP: send %s\n", ppp_code(*q
));
2248 tunnelsend(b
, l
+ (q
- b
), t
);
2249 change_state(s
, ccp
, Stopped
);
2251 else if (*p
!= CodeRej
)
2253 ppp_code_rej(s
, t
, PPPCCP
, "CCP", p
, l
, b
, sizeof(b
));
2257 // send a CHAP challenge
2258 void sendchap(sessionidt s
, tunnelidt t
)
2260 uint8_t b
[MAXETHER
];
2269 LOG(1, s
, t
, "No RADIUS to send challenge\n");
2270 STAT(tunnel_tx_errors
);
2274 LOG(1, s
, t
, "Send CHAP challenge\n");
2276 radius
[r
].chap
= 1; // CHAP not PAP
2278 if (radius
[r
].state
!= RADIUSCHAP
)
2281 radius
[r
].state
= RADIUSCHAP
;
2282 radius
[r
].retry
= backoff(radius
[r
].try++);
2283 if (radius
[r
].try > 5)
2285 sessionshutdown(s
, "CHAP timeout.", CDN_ADMIN_DISC
, TERM_REAUTHENTICATION_FAILURE
);
2286 STAT(tunnel_tx_errors
);
2289 q
= makeppp(b
, sizeof(b
), 0, 0, s
, t
, PPPCHAP
, 0, 0, 0);
2292 *q
= 1; // challenge
2293 q
[1] = radius
[r
].id
; // ID
2294 q
[4] = 16; // value size (size of challenge)
2295 memcpy(q
+ 5, radius
[r
].auth
, 16); // challenge
2296 strcpy((char *) q
+ 21, hostname
); // our name
2297 *(uint16_t *) (q
+ 2) = htons(strlen(hostname
) + 21); // length
2298 tunnelsend(b
, strlen(hostname
) + 21 + (q
- b
), t
); // send it
2301 // fill in a L2TP message with a PPP frame,
2302 // returns start of PPP frame
2303 uint8_t *makeppp(uint8_t *b
, int size
, uint8_t *p
, int l
, sessionidt s
, tunnelidt t
, uint16_t mtype
, uint8_t prio
, bundleidt bid
, uint8_t mp_bits
)
2305 uint16_t hdr
= 0x0002; // L2TP with no options
2306 uint16_t type
= mtype
;
2309 if (size
< 16) // Need more space than this!!
2311 LOG(0, s
, t
, "makeppp buffer too small for L2TP header (size=%d)\n", size
);
2315 if (prio
) hdr
|= 0x0100; // set priority bit
2317 *(uint16_t *) (b
+ 0) = htons(hdr
);
2318 *(uint16_t *) (b
+ 2) = htons(tunnel
[t
].far
); // tunnel
2319 *(uint16_t *) (b
+ 4) = htons(session
[s
].far
); // session
2322 // Check whether this session is part of multilink
2325 if (bundle
[bid
].num_of_links
> 1)
2326 type
= PPPMP
; // Change PPP message type to the PPPMP
2331 if (type
== PPPLCP
|| !(session
[s
].flags
& SESSION_ACFC
))
2333 *(uint16_t *) b
= htons(0xFF03); // HDLC header
2337 if (type
< 0x100 && session
[s
].flags
& SESSION_PFC
)
2343 *(uint16_t *) b
= htons(type
);
2349 // Set the sequence number and (B)egin (E)nd flags
2350 if (session
[s
].mssf
)
2352 // Set the multilink bits
2353 uint16_t bits_send
= mp_bits
;
2354 *(uint16_t *) b
= htons((bundle
[bid
].seq_num_t
& 0x0FFF)|bits_send
);
2359 *(uint32_t *) b
= htonl(bundle
[bid
].seq_num_t
);
2360 // Set the multilink bits
2365 bundle
[bid
].seq_num_t
++;
2367 // Add the message type if this fragment has the begin bit set
2368 if (mp_bits
& MP_BEGIN
)
2370 //*b++ = mtype; // The next two lines are instead of this
2371 *(uint16_t *) b
= htons(mtype
); // Message type
2376 if ((b
- start
) + l
> size
)
2378 LOG(2, s
, t
, "makeppp would overflow buffer (size=%d, header+payload=%td)\n", size
, (b
- start
) + l
);
2389 static int add_lcp_auth(uint8_t *b
, int size
, int authtype
)
2392 if ((authtype
== AUTHCHAP
&& size
< 5) || size
< 4)
2395 *b
++ = 3; // Authentication-Protocol
2396 if (authtype
== AUTHCHAP
)
2398 len
= *b
++ = 5; // length
2399 *(uint16_t *) b
= htons(PPPCHAP
); b
+= 2;
2402 else if (authtype
== AUTHPAP
)
2404 len
= *b
++ = 4; // length
2405 *(uint16_t *) b
= htons(PPPPAP
); b
+= 2;
2409 LOG(0, 0, 0, "add_lcp_auth called with unsupported auth type %d\n", authtype
);
2415 // Send LCP ConfigReq for MRU, authentication type and magic no
2416 void sendlcp(sessionidt s
, tunnelidt t
)
2418 uint8_t b
[500], *q
, *l
;
2419 int authtype
= sess_local
[s
].lcp_authtype
;
2421 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, s
, t
, PPPLCP
, 0, 0, 0)))
2424 LOG(3, s
, t
, "LCP: send ConfigReq%s%s%s including MP options\n",
2425 authtype
? " (" : "",
2426 authtype
? (authtype
== AUTHCHAP
? "CHAP" : "PAP") : "",
2427 authtype
? ")" : "");
2431 *l
++ = ++sess_local
[s
].lcp_ident
; // ID
2433 l
+= 2; //Save space for length
2435 if (sess_local
[s
].ppp_mru
)
2437 *l
++ = 1; *l
++ = 4; // Maximum-Receive-Unit (length 4)
2438 *(uint16_t *) l
= htons(sess_local
[s
].ppp_mru
); l
+= 2;
2442 l
+= add_lcp_auth(l
, sizeof(b
) - (l
- b
), authtype
);
2444 if (session
[s
].magic
)
2446 *l
++ = 5; *l
++ = 6; // Magic-Number (length 6)
2447 *(uint32_t *) l
= htonl(session
[s
].magic
);
2451 if (sess_local
[s
].mp_mrru
)
2453 *l
++ = 17; *l
++ = 4; // Multilink Max-Receive-Reconstructed-Unit (length 4)
2454 *(uint16_t *) l
= htons(sess_local
[s
].mp_mrru
); l
+= 2;
2457 if (sess_local
[s
].mp_epdis
)
2459 *l
++ = 19; *l
++ = 7; // Multilink Endpoint Discriminator (length 7)
2460 *l
++ = IPADDR
; // Endpoint Discriminator class
2461 *(uint32_t *) l
= htonl(sess_local
[s
].mp_epdis
);
2465 *(uint16_t *)(q
+ 2) = htons(l
- q
); // Length
2467 LOG_HEX(5, "PPPLCP", q
, l
- q
);
2468 if (config
->debug
> 3) dumplcp(q
, l
- q
);
2470 tunnelsend(b
, (l
- b
), t
);
2471 restart_timer(s
, lcp
);
2474 // Send CCP request for no compression
2475 void sendccp(sessionidt s
, tunnelidt t
)
2479 if (!(q
= makeppp(b
, sizeof(b
), NULL
, 0, s
, t
, PPPCCP
, 0, 0, 0)))
2482 LOG(3, s
, t
, "CCP: send ConfigReq (no compression)\n");
2485 *(q
+ 1) = ++sess_local
[s
].lcp_ident
; // ID
2486 *(uint16_t *)(q
+ 2) = htons(4); // Length
2488 LOG_HEX(5, "PPPCCP", q
, 4);
2489 tunnelsend(b
, (q
- b
) + 4 , t
);
2490 restart_timer(s
, ccp
);
2493 // Reject unknown/unconfigured protocols
2494 void protoreject(sessionidt s
, tunnelidt t
, uint8_t *p
, uint16_t l
, uint16_t proto
)
2497 uint8_t buf
[MAXETHER
];
2499 int mru
= session
[s
].mru
;
2500 if (mru
< MINMTU
) mru
= MINMTU
;
2501 if (mru
> sizeof(buf
)) mru
= sizeof(buf
);
2504 if (l
> mru
) l
= mru
;
2506 q
= makeppp(buf
, sizeof(buf
), 0, 0, s
, t
, PPPLCP
, 0, 0, 0);
2510 *(q
+ 1) = ++sess_local
[s
].lcp_ident
;
2511 *(uint16_t *)(q
+ 2) = htons(l
);
2512 *(uint16_t *)(q
+ 4) = htons(proto
);
2513 memcpy(q
+ 6, p
, l
- 6);
2515 if (proto
== PPPIPV6CP
)
2516 LOG(3, s
, t
, "LCP: send ProtocolRej (IPV6CP: not configured)\n");
2518 LOG(2, s
, t
, "LCP: sent ProtocolRej (0x%04X: unsupported)\n", proto
);
2520 tunnelsend(buf
, l
+ (q
- buf
), t
);