fix code-reject/protocol-reject
[l2tpns.git] / l2tpns.c
index 8b2bffd..ed9424c 100644 (file)
--- 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.127 2005-09-01 06:59:06 bodea Exp $";
+char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.130 2005-09-13 14:23:07 bodea Exp $";
 
 #include <arpa/inet.h>
 #include <assert.h>
@@ -135,6 +135,7 @@ config_descriptt config_values[] = {
        CONFIG("packet_limit", max_packets, INT),
        CONFIG("cluster_address", cluster_address, IPv4),
        CONFIG("cluster_interface", cluster_interface, STRING),
+       CONFIG("cluster_mcast_ttl", cluster_mcast_ttl, INT),
        CONFIG("cluster_hb_interval", cluster_hb_interval, INT),
        CONFIG("cluster_hb_timeout", cluster_hb_timeout, INT),
        CONFIG("cluster_master_min_adv", cluster_master_min_adv, INT),
@@ -1826,6 +1827,11 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr)
                return;
        }
        l -= (p - buf);
+
+       // used to time out old tunnels
+       if (t && tunnel[t].state == TUNNELOPEN)
+               tunnel[t].lastrec = time_now;
+
        if (*buf & 0x80)
        {                          // control
                uint16_t message = 0xFFFF;      // message type
@@ -1913,9 +1919,6 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr)
                        return;
                }
 
-               // This is used to time out old tunnels
-               tunnel[t].lastrec = time_now;
-
                // check sequence of this message
                {
                        int skip = tunnel[t].window; // track how many in-window packets are still in queue
@@ -2480,7 +2483,7 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr)
                        if (!config->cluster_iam_master) { master_forward_packet(buf, len, addr->sin_addr.s_addr, addr->sin_port); return; }
                        processipcp(s, t, p, l);
                }
-               else if (prot == PPPIPV6CP)
+               else if (prot == PPPIPV6CP && config->ipv6_prefix.s6_addr[0])
                {
                        session[s].last_packet = time_now;
                        if (!config->cluster_iam_master) { master_forward_packet(buf, len, addr->sin_addr.s_addr, addr->sin_port); return; }
@@ -2509,13 +2512,8 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr)
 
                        processipin(s, t, p, l);
                }
-               else if (prot == PPPIPV6)
+               else if (prot == PPPIPV6 && config->ipv6_prefix.s6_addr[0])
                {
-                       if (!config->ipv6_prefix.s6_addr[0])
-                       {
-                               LOG(1, s, t, "IPv6 not configured; yet received IPv6 packet. Ignoring.\n");
-                               return;
-                       }
                        if (session[s].die)
                        {
                                LOG(4, s, t, "Session %d is closing.  Don't process PPP packets\n", s);
@@ -2531,10 +2529,40 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr)
 
                        processipv6in(s, t, p, l);
                }
+               else if (session[s].ppp.lcp == Opened)
+               {
+                       uint8_t
+                       uint8_t *q;
+                       int mru = session[s].mru;
+
+                       if (!mru) mru = MAXMRU;
+                       if (mru > size) mru = size;
+
+                       l += 6;
+                       if (l > mru) l = mru;
+
+                       q = makeppp(buf, size, 0, 0, s, t, proto);
+                       if (!q) return;
+
+                       *q = CodeRej;
+                       *(q + 1) = ++sess_local[s].lcp_ident;
+                       *(uint16_t *)(q + 2) = l;
+                       *(uint16_t *)(q + 4) = htons(proto);
+                       memcpy(q + 6, p, l - 6);
+
+                       if (prot == PPPIPV6CP)
+                               LOG(3, s, t, "LCP: send ProtocolRej (IPV6CP: not configured)\n");
+                       else
+                               LOG(2, s, t, "LCP: sent ProtocolRej (0x%04X: unsupported)\n", prot);
+
+                       if (config->debug > 3) dumplcp(q, l);
+
+                       tunnelsend(buf, l + (q - buf), t);
+               }
                else
                {
-                       STAT(tunnel_rx_errors);
-                       LOG(1, s, t, "Unknown PPP protocol %04X\n", prot);
+                       LOG(2, s, t, "Unknown PPP protocol 0x%04X received in LCP %s state\n",
+                               prot, ppp_state(session[s].ppp.lcp));
                }
        }
 }
@@ -3469,6 +3497,7 @@ static void initdata(int optdebug, char *optconfig)
        config->debug = optdebug;
        config->num_tbfs = MAXTBFS;
        config->rl_rate = 28; // 28kbps
+       config->cluster_mcast_ttl = 1;
        config->cluster_master_min_adv = 1;
        config->ppp_restart_time = 3;
        config->ppp_max_configure = 10;