+ return;
+
+ tunnelsend(b, l + (q - b), t); // send it
+ }
+ }
+}
+
+// Process IPV6CP messages
+void processipv6cp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l)
+{
+
+ CSTAT(processipv6cp);
+
+ LOG_HEX(5, "IPV6CP", p, l);
+ if (l < 4)
+ {
+ LOG(1, s, t, "Short IPV6CP %d bytes\n", l);
+ STAT(tunnel_rx_errors);
+ return ;
+ }
+ if (*p == ConfigAck)
+ {
+ // happy with our IPV6CP
+ session[s].flags |= SF_IPV6CP_ACKED;
+
+ LOG(3, s, t, "IPV6CP Acked, IPv6 is now active\n");
+ // Add a routed block if configured.
+ if (session[s].ipv6prefixlen)
+ {
+ route6set(s, session[s].ipv6route, session[s].ipv6prefixlen, 1);
+ session[s].flags |= SF_IPV6_ROUTED;
+ }
+
+ // Send an initial RA (TODO: Should we send these regularly?)
+ send_ipv6_ra(t, s, NULL);
+ return;
+ }
+ if (*p != ConfigReq)
+ {
+ LOG(1, s, t, "Unexpected IPV6CP code %d\n", *p);
+ STAT(tunnel_rx_errors);
+ return;
+ }
+
+ LOG(4, s, t, "IPV6CP ConfigReq received\n");
+ if (ntohs(*(uint16_t *) (p + 2)) > l)
+ {
+ LOG(1, s, t, "Length mismatch IPV6CP %d/%d\n", ntohs(*(uint16_t *) (p + 2)), l);
+ STAT(tunnel_rx_errors);
+ return ;
+ }
+ if (!session[s].ip)
+ {
+ LOG(3, s, t, "Waiting on radius reply\n");
+ return; // have to wait on RADIUS reply
+ }
+ // form a config reply quoting the IP in the session
+ {
+ uint8_t b[MAXCONTROL];
+ uint8_t *i,
+ *q;
+
+ l = ntohs(*(uint16_t *) (p + 2)); // We must use length from IPV6CP len field
+ q = p + 4;
+ i = p + l;
+ while (q < i && q[1])
+ {
+ if (*q != 1)
+ break;
+ q += q[1];
+ }
+ if (q < i)
+ {
+ // reject
+ uint16_t n = 4;
+ i = p + l;
+ if (!(q = makeppp(b, sizeof(b), p, l, t, s, PPPIPV6CP)))
+ {
+ LOG(2, s, t, "Failed to send IPV6CP ConfigRej\n");
+ return;
+ }
+ *q = ConfigRej;
+ p += 4;
+ while (p < i && p[1])