X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/14013054f38b44ed80237772299acbd405eb00c3..caeeb2635b57904e554e046815fa16ab5c3749db:/l2tpns.c diff --git a/l2tpns.c b/l2tpns.c index c0a60a7..a83b57d 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -4,7 +4,7 @@ // Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced // vim: sw=8 ts=8 -char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.37 2004-11-02 04:35:04 bodea Exp $"; +char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.41 2004-11-04 06:05:55 bodea Exp $"; #include #include @@ -23,6 +23,7 @@ char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.37 2004-11-02 04:35:04 bodea Exp #include #include #include +#include #include #include #include @@ -239,7 +240,7 @@ void _log(int level, ipt address, sessionidt s, tunnelidt t, const char *format, va_end(ap); } -void _log_hex(int level, ipt address, sessionidt s, tunnelidt t, const char *title, const char *data, int maxsize) +void _log_hex(int level, const char *title, const char *data, int maxsize) { int i, j; const u8 *d = (const u8 *)data; @@ -249,7 +250,7 @@ void _log_hex(int level, ipt address, sessionidt s, tunnelidt t, const char *tit // No support for log_hex to syslog if (log_stream) { - log(level, address, s, t, "%s (%d bytes):\n", title, maxsize); + _log(level, 0, 0, 0, "%s (%d bytes):\n", title, maxsize); setvbuf(log_stream, NULL, _IOFBF, 16384); for (i = 0; i < maxsize; ) @@ -1003,7 +1004,7 @@ void throttle_session(sessionidt s, int rate_in, int rate_out) free_tbf(session[s].tbf_out); if (rate_out > 0) - session[s].tbf_out = new_tbf(s, bytes * 2, bytes, send_ipin); + session[s].tbf_out = new_tbf(s, bytes * 2, bytes, send_ipout); else session[s].tbf_out = 0; @@ -1923,27 +1924,12 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } else if (prot == PPPIP) { - if (!config->cluster_iam_master) + session[s].last_packet = time_now; + if (session[s].walled_garden && !config->cluster_iam_master) { - // We're a slave. Should we forward this packet to the master? - - // Is this a walled garden session, or something that needs it's - // idle time updated?? - - // Maintain the idle timeouts on the master. If this would - // significantly reset the idletimeout, run it via the master - // to refresh the master's idle timer. - // Not sure this is ideal: It may re-order packets. - - if (session[s].walled_garden || (session[s].last_packet + (ECHO_TIMEOUT/2)) < time_now) - { - master_forward_packet(buf, len, addr->sin_addr.s_addr, addr->sin_port); - session[s].last_packet = time_now; - return; - } - // fall through to processipin. - } else - session[s].last_packet = time_now; + master_forward_packet(buf, len, addr->sin_addr.s_addr, addr->sin_port); + return; + } processipin(t, s, p, l); } else @@ -2442,6 +2428,71 @@ void mainloop(void) // Important!!! We MUST not process any packets past this point! } +static void stripdomain(char *host) +{ + char *p; + + if ((p = strchr(host, '.'))) + { + char *domain = 0; + char _domain[1024]; + + // strip off domain + FILE *resolv = fopen("/etc/resolv.conf", "r"); + if (resolv) + { + char buf[1024]; + char *b; + + while (fgets(buf, sizeof(buf), resolv)) + { + if (strncmp(buf, "domain", 6) && strncmp(buf, "search", 6)) + continue; + + if (!isspace(buf[6])) + continue; + + b = buf + 7; + while (isspace(*b)) b++; + + if (*b) + { + char *d = b; + while (*b && !isspace(*b)) b++; + *b = 0; + if (buf[0] == 'd') // domain is canonical + { + domain = d; + break; + } + + // first search line + if (!domain) + { + // hold, may be subsequent domain line + strncpy(_domain, d, sizeof(_domain))[sizeof(_domain)-1] = 0; + domain = _domain; + } + } + } + + fclose(resolv); + } + + if (domain) + { + int hl = strlen(host); + int dl = strlen(domain); + if (dl < hl && host[hl - dl - 1] == '.' && !strcmp(host + hl - dl, domain)) + host[hl -dl - 1] = 0; + } + else + { + *p = 0; // everything after first dot + } + } +} + // Init data structures void initdata(int optdebug, char *optconfig) { @@ -2536,10 +2587,9 @@ void initdata(int optdebug, char *optconfig) if (!*hostname) { - char *p; // Grab my hostname unless it's been specified gethostname(hostname, sizeof(hostname)); - if ((p = strchr(hostname, '.'))) *p = 0; + stripdomain(hostname); } _statistics->start_time = _statistics->last_reset = time(NULL); @@ -3523,15 +3573,14 @@ int sessionsetup(tunnelidt t, sessionidt s) if (!session[s].ip || session[s].ip == 0xFFFFFFFE) { assign_ip_address(s); - if (session[s].ip) - log(3, 0, s, t, " No IP allocated. Assigned %s from pool\n", - inet_toa(htonl(session[s].ip))); - else + if (!session[s].ip) { log(0, 0, s, t, " No IP allocated. The IP address pool is FULL!\n"); sessionshutdown(s, "No IP addresses available"); return 0; } + log(3, 0, s, t, " No IP allocated. Assigned %s from pool\n", + inet_toa(htonl(session[s].ip))); }