X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/57d13b822213468bc61f3916eda4e448196c14db..00ac71ac0835ec1dd2413508d5be8069ac208f7f:/ppp.c diff --git a/ppp.c b/ppp.c index b2d84ec..a169512 100644 --- a/ppp.c +++ b/ppp.c @@ -1,6 +1,6 @@ // L2TPNS PPP Stuff -char const *cvs_id_ppp = "$Id: ppp.c,v 1.22 2004-11-05 23:18:54 bodea Exp $"; +char const *cvs_id_ppp = "$Id: ppp.c,v 1.27 2004-11-18 13:15:28 bodea Exp $"; #include #include @@ -23,7 +23,7 @@ extern u32 eth_tx; extern time_t time_now; extern struct configt *config; -void sendccp(tunnelidt t, sessionidt s); +static void sendccp(tunnelidt t, sessionidt s); // Process PAP messages void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l) @@ -224,7 +224,7 @@ void processchap(tunnelidt t, sessionidt s, u8 *p, u16 l) radiussend(r, RADIUSAUTH); } -char *ppp_lcp_types[] = { +static char *ppp_lcp_types[] = { NULL, "ConfigReq", "ConfigAck", @@ -240,7 +240,7 @@ char *ppp_lcp_types[] = { "IdentRequest", }; -void dumplcp(u8 *p, int l) +static void dumplcp(u8 *p, int l) { int x = l - 4; u8 *o = (p + 4); @@ -543,6 +543,26 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) } } +// find a PPP option, returns point to option, or 0 if not found +static u8 *findppp(u8 *b, u8 mtype) +{ + u16 l = ntohs(*(u16 *) (b + 2)); + if (l < 4) + return 0; + b += 4; + l -= 4; + while (l) + { + if (l < b[1] || !b[1]) + return 0; // faulty + if (*b == mtype) + return b; + l -= b[1]; + b += b[1]; + } + return 0; +} + // Process IPCP messages void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) { @@ -580,6 +600,10 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) session[s].flags |= SF_IPCP_ACKED; LOG(3, session[s].ip, s, t, "IPCP Acked, session is now active\n"); + + // clear LCP_ACKED flag for possible fast renegotiaion for routers + session[s].flags &= ~SF_LCP_ACKED; + return; } if (*p != ConfigReq) @@ -709,12 +733,6 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l) return; } - if (session[s].snoop_ip && session[s].snoop_port) - { - // Snooping this session - snoop_send_packet(p, l, session[s].snoop_ip, session[s].snoop_port); - } - // Add on the tun header p -= 4; *(u32 *)p = htonl(0x00000800); @@ -725,16 +743,6 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l) return; } - session[s].cin += l - 4; - session[s].total_cin += l - 4; - sess_count[s].cin += l - 4; - - session[s].pin++; - eth_tx += l - 4; - - STAT(tun_tx_packets); - INC_STAT(tun_tx_bytes, l); - if (session[s].tbf_in && config->cluster_iam_master) { // Are we throttled and a master?? actually handle the throttled packets. tbf_queue_packet(session[s].tbf_in, p, l); return; @@ -746,8 +754,25 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l) STAT(tun_tx_errors); LOG(0, 0, s, t, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n", l, strerror(errno), tunfd, p); + + return; } + if (session[s].snoop_ip && session[s].snoop_port) + { + // Snooping this session + snoop_send_packet(p + 4, l - 4, session[s].snoop_ip, session[s].snoop_port); + } + + session[s].cin += l - 4; + session[s].total_cin += l - 4; + sess_count[s].cin += l - 4; + + session[s].pin++; + eth_tx += l - 4; + + STAT(tun_tx_packets); + INC_STAT(tun_tx_bytes, l - 4); } // @@ -757,11 +782,20 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l) void send_ipin(sessionidt s, u8 *buf, int len) { LOG_HEX(5, "IP in throttled", buf, len); + if (write(tunfd, buf, len) < 0) { STAT(tun_tx_errors); LOG(0, 0, 0, 0, "Error writing %d bytes to TUN device: %s (tunfd=%d, p=%p)\n", len, strerror(errno), tunfd, buf); + + return; + } + + if (session[s].snoop_ip && session[s].snoop_port) + { + // Snooping this session + snoop_send_packet(buf + 4, len - 4, session[s].snoop_ip, session[s].snoop_port); } // Increment packet counters @@ -771,6 +805,9 @@ void send_ipin(sessionidt s, u8 *buf, int len) session[s].pin++; eth_tx += len - 4; + + STAT(tun_tx_packets); + INC_STAT(tun_tx_bytes, len - 4); } @@ -807,7 +844,7 @@ void processccp(tunnelidt t, sessionidt s, u8 *p, u16 l) *p = TerminateAck; // close if (!(q = makeppp(b, sizeof(b), p, l, t, s, PPPCCP))) { - LOG(1,0,0,0, "Failed to send CCP packet.\n"); + LOG(1,0,0,0, "Failed to send CCP packet.\n"); return; } tunnelsend(b, l + (q - b), t); // send it @@ -897,26 +934,6 @@ u8 *makeppp(u8 *b, int size, u8 *p, int l, tunnelidt t, sessionidt s, u16 mtype) return b; } -// find a PPP option, returns point to option, or 0 if not found -u8 *findppp(u8 *b, u8 mtype) -{ - u16 l = ntohs(*(u16 *) (b + 2)); - if (l < 4) - return 0; - b += 4; - l -= 4; - while (l) - { - if (l < b[1] || !b[1]) - return 0; // faulty - if (*b == mtype) - return b; - l -= b[1]; - b += b[1]; - } - return 0; -} - // Send initial LCP ConfigReq void initlcp(tunnelidt t, sessionidt s) { @@ -942,7 +959,7 @@ void initlcp(tunnelidt t, sessionidt s) } // Send CCP reply -void sendccp(tunnelidt t, sessionidt s) +static void sendccp(tunnelidt t, sessionidt s) { char *q, b[500] = {0};