Remove BFD from master-branch (kept in BFD-branch)
authorSteven Barth <steven@midlink.org>
Wed, 13 Aug 2014 11:30:42 +0000 (13:30 +0200)
committerSteven Barth <steven@midlink.org>
Wed, 13 Aug 2014 11:30:42 +0000 (13:30 +0200)
CMakeLists.txt
src/bfd.c [deleted file]
src/bfd.h [deleted file]
src/odhcp6c.c

index e0abe0807f0aad6c79ef5d1345de2892f133874f..9e508f17415874b767c96f1d534c1d151d4d8db4 100644 (file)
@@ -19,12 +19,7 @@ if(${EXT_S46})
        add_definitions(-DEXT_S46=${EXT_S46})
 endif(${EXT_S46})
 
-if(${EXT_BFD_PING})
-       add_definitions(-DEXT_BFD_PING)
-       set(BFD_SOURCE src/bfd.c)
-endif(${EXT_BFD_PING})
-
-add_executable(odhcp6c src/odhcp6c.c src/dhcpv6.c src/ra.c src/script.c src/md5.c ${BFD_SOURCE})
+add_executable(odhcp6c src/odhcp6c.c src/dhcpv6.c src/ra.c src/script.c src/md5.c)
 target_link_libraries(odhcp6c resolv)
 
 # Installation
diff --git a/src/bfd.c b/src/bfd.c
deleted file mode 100644 (file)
index 1822555..0000000
--- a/src/bfd.c
+++ /dev/null
@@ -1,211 +0,0 @@
-#include <syslog.h>
-#include <signal.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-
-#include <sys/socket.h>
-#include <net/if.h>
-#include <net/ethernet.h>
-#include <netpacket/packet.h>
-#include <linux/rtnetlink.h>
-#include <linux/filter.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "odhcp6c.h"
-
-static int sock = -1, rtnl = -1;
-static int if_index = -1;
-static int bfd_failed = 0, bfd_limit = 0, bfd_interval = 0;
-static bool bfd_armed = false;
-
-
-static void bfd_send(int signal __attribute__((unused)))
-{
-       struct {
-               struct ip6_hdr ip6;
-               struct icmp6_hdr icmp6;
-       } ping;
-       memset(&ping, 0, sizeof(ping));
-
-       ping.ip6.ip6_vfc = 6 << 4;
-       ping.ip6.ip6_plen = htons(8);
-       ping.ip6.ip6_nxt = IPPROTO_ICMPV6;
-       ping.ip6.ip6_hlim = 255;
-
-       ping.icmp6.icmp6_type = ICMP6_ECHO_REQUEST;
-       ping.icmp6.icmp6_data32[0] = htonl(0xbfd0bfd);
-
-       size_t pdlen, rtlen;
-       struct odhcp6c_entry *pd = odhcp6c_get_state(STATE_IA_PD, &pdlen), *cpd = NULL;
-       struct odhcp6c_entry *rt = odhcp6c_get_state(STATE_RA_ROUTE, &rtlen), *crt = NULL;
-       bool crt_found = false;
-
-       alarm(bfd_interval);
-
-       if (bfd_armed) {
-               if (++bfd_failed > bfd_limit) {
-                       raise(SIGUSR2);
-                       return;
-               }
-       }
-
-       // Detect PD-Prefix
-       for (size_t i = 0; i < pdlen / sizeof(*pd); ++i)
-               if (!cpd || ((cpd->target.s6_addr[0] & 7) == 0xfc) > ((pd[i].target.s6_addr[0] & 7) == 0xfc)
-                               || cpd->preferred < pd[i].preferred)
-                       cpd = &pd[i];
-
-       // Detect default router
-       for (size_t i = 0; i < rtlen / sizeof(*rt); ++i)
-               if (IN6_IS_ADDR_UNSPECIFIED(&rt[i].target) && (!crt || crt->priority > rt[i].priority))
-                       crt = &rt[i];
-
-       struct sockaddr_ll dest = {
-               .sll_family = AF_PACKET,
-               .sll_protocol = htons(ETH_P_IPV6),
-               .sll_ifindex = if_index,
-               .sll_halen = ETH_ALEN,
-       };
-
-       if (crt) {
-               struct {
-                       struct nlmsghdr hdr;
-                       struct ndmsg ndm;
-               } req = {
-                       .hdr = {sizeof(req), RTM_GETNEIGH, NLM_F_REQUEST | NLM_F_DUMP, 1, 0},
-                       .ndm = {.ndm_family = AF_INET6, .ndm_ifindex = if_index}
-               };
-               send(rtnl, &req, sizeof(req), 0);
-
-               uint8_t buf[8192];
-               struct nlmsghdr *nhm;
-               do {
-                       ssize_t read = recv(rtnl, buf, sizeof(buf), 0);
-                       nhm = (struct nlmsghdr*)buf;
-                       if ((read < 0 && errno == EINTR) || !NLMSG_OK(nhm, (size_t)read))
-                               continue;
-                       else if (read < 0)
-                               break;
-
-                       for (; read > 0 && NLMSG_OK(nhm, (size_t)read); nhm = NLMSG_NEXT(nhm, read)) {
-                               ssize_t attrlen = NLMSG_PAYLOAD(nhm, sizeof(struct ndmsg));
-                               if (nhm->nlmsg_type != RTM_NEWNEIGH || attrlen <= 0) {
-                                       nhm = NULL;
-                                       break;
-                               }
-
-                               // Already have our MAC
-                               if (crt_found)
-                                       continue;
-
-                               struct ndmsg *ndm = NLMSG_DATA(nhm);
-                               for (struct rtattr *rta = (struct rtattr*)&ndm[1];
-                                               attrlen > 0 && RTA_OK(rta, (size_t)attrlen);
-                                               rta = RTA_NEXT(rta, attrlen)) {
-                                       if (rta->rta_type == NDA_DST) {
-                                               crt_found = IN6_ARE_ADDR_EQUAL(RTA_DATA(rta), &crt->router);
-                                       } else if (rta->rta_type == NDA_LLADDR) {
-                                               memcpy(dest.sll_addr, RTA_DATA(rta), ETH_ALEN);
-                                       }
-                               }
-                       }
-               } while (nhm);
-       }
-
-       if (!crt_found || !cpd)
-               return;
-
-       ping.ip6.ip6_src = cpd->target;
-       ping.ip6.ip6_dst = cpd->target;
-
-       struct sock_filter bpf[] = {
-               BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct ip6_hdr, ip6_plen)),
-               BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8 << 16 | IPPROTO_ICMPV6 << 8 | 254, 0, 13),
-               BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct ip6_hdr, ip6_dst)),
-               BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ntohl(ping.ip6.ip6_dst.s6_addr32[0]), 0, 11),
-               BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct ip6_hdr, ip6_dst) + 4),
-               BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ntohl(ping.ip6.ip6_dst.s6_addr32[1]), 0, 9),
-               BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct ip6_hdr, ip6_dst) + 8),
-               BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ntohl(ping.ip6.ip6_dst.s6_addr32[2]), 0, 7),
-               BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct ip6_hdr, ip6_dst) + 12),
-               BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ntohl(ping.ip6.ip6_dst.s6_addr32[3]), 0, 5),
-               BPF_STMT(BPF_LD | BPF_W | BPF_ABS, sizeof(struct ip6_hdr) +
-                               offsetof(struct icmp6_hdr, icmp6_type)),
-               BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ICMP6_ECHO_REQUEST << 24, 0, 3),
-               BPF_STMT(BPF_LD | BPF_W | BPF_ABS, sizeof(struct ip6_hdr) +
-                               offsetof(struct icmp6_hdr, icmp6_data32)),
-               BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ntohl(ping.icmp6.icmp6_data32[0]), 0, 1),
-               BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
-               BPF_STMT(BPF_RET | BPF_K, 0),
-       };
-       struct sock_fprog bpf_prog = {sizeof(bpf) / sizeof(*bpf), bpf};
-
-
-       if (sock < 0) {
-               sock = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IPV6));
-               bind(sock, (struct sockaddr*)&dest, sizeof(dest));
-
-               fcntl(sock, F_SETOWN, getpid());
-               fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_ASYNC);
-       }
-
-       setsockopt(sock, SOL_SOCKET, SO_DETACH_FILTER, &bpf_prog, sizeof(bpf_prog));
-       if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_prog, sizeof(bpf_prog))) {
-               close(sock);
-               sock = -1;
-               return;
-       }
-
-       uint8_t dummy[8];
-       while (recv(sock, dummy, sizeof(dummy), MSG_DONTWAIT | MSG_TRUNC) > 0);
-
-       sendto(sock, &ping, sizeof(ping), MSG_DONTWAIT,
-                       (struct sockaddr*)&dest, sizeof(dest));
-}
-
-
-void bfd_receive(void)
-{
-       uint8_t dummy[8];
-       while (recv(sock, dummy, sizeof(dummy), MSG_DONTWAIT | MSG_TRUNC) > 0) {
-               bfd_failed = 0;
-               bfd_armed = true;
-       }
-}
-
-
-int bfd_start(const char *ifname, int limit, int interval)
-{
-       if_index = if_nametoindex(ifname);
-       bfd_armed = false;
-       bfd_failed = 0;
-       bfd_limit = limit;
-       bfd_interval = interval;
-
-       if (limit < 1 || interval < 1)
-               return 0;
-
-       rtnl = socket(AF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE);
-       struct sockaddr_nl rtnl_kernel = { .nl_family = AF_NETLINK };
-       connect(rtnl, (const struct sockaddr*)&rtnl_kernel, sizeof(rtnl_kernel));
-
-       signal(SIGALRM, bfd_send);
-       alarm(5);
-       return 0;
-}
-
-
-void bfd_stop(void)
-{
-       alarm(0);
-       close(sock);
-       close(rtnl);
-
-       sock = -1;
-       rtnl = -1;
-}
diff --git a/src/bfd.h b/src/bfd.h
deleted file mode 100644 (file)
index 0d3616a..0000000
--- a/src/bfd.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Copyright (C) 2012-2013 Steven Barth <steven@midlink.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License v2 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-#pragma once
-
-int bfd_start(const char *ifname, int limit, int interval);
-void bfd_receive(void);
-void bfd_stop(void);
index f1286e5e93b70f2c2f7a56471e898abe70480267..2357a9a9aa577b7b58819c599c341b4c85e9abc8 100644 (file)
@@ -32,9 +32,6 @@
 #include "odhcp6c.h"
 #include "ra.h"
 
-#ifdef EXT_BFD_PING
-#include "bfd.h"
-#endif
 
 
 static void sighandler(int signal);
@@ -70,9 +67,6 @@ int main(_unused int argc, char* const argv[])
        static struct in6_addr ifid = IN6ADDR_ANY_INIT;
        int sol_timeout = DHCPV6_SOL_MAX_RT;
 
-#ifdef EXT_BFD_PING
-       int bfd_interval = 0, bfd_loss = 3;
-#endif
 
        bool help = false, daemonize = false;
        int logopt = LOG_PID;
@@ -141,12 +135,6 @@ int main(_unused int argc, char* const argv[])
                        ia_pd_mode = IA_MODE_FORCE;
                        break;
 
-#ifdef EXT_BFD_PING
-               case 'B':
-                       bfd_interval = atoi(optarg);
-                       break;
-#endif
-
                case 'c':
                        l = script_unhexlify(&buf[4], sizeof(buf) - 4, optarg);
                        if (l > 0) {
@@ -350,10 +338,6 @@ int main(_unused int argc, char* const argv[])
                        script_call("bound");
                        bound = true;
                        syslog(LOG_NOTICE, "entering stateful-mode on %s", ifname);
-#ifdef EXT_BFD_PING
-                       if (bfd_interval > 0)
-                               bfd_start(ifname, bfd_loss, bfd_interval);
-#endif
 
                        while (!signal_usr2 && !signal_term) {
                                // Renew Cycle
@@ -396,9 +380,6 @@ int main(_unused int argc, char* const argv[])
                                if (res > 0)
                                        script_call("rebound");
                                else {
-#ifdef EXT_BFD_PING
-                                       bfd_stop();
-#endif
                                        break;
                                }
                        }
@@ -439,9 +420,6 @@ static int usage(void)
        "       -P <length>     Request IPv6-Prefix (0 = auto)\n"
        "       -F              Force IPv6-Prefix\n"
        "       -V <class>      Set vendor-class option (base-16 encoded)\n"
-#ifdef EXT_BFD_PING
-       "       -B <interval>   Enable BFD ping check\n"
-#endif
        "       -u <user-class> Set user-class option string\n"
        "       -c <clientid>   Override client-ID (base-16 encoded)\n"
        "       -i <iface-id>   Use a custom interface identifier for RA handling\n"
@@ -505,9 +483,6 @@ bool odhcp6c_signal_process(void)
                else if (ra_updated && !bound && allow_slaac_only > 0)
                        script_delay_call("ra-updated", allow_slaac_only);
 
-#ifdef EXT_BFD_PING
-               bfd_receive();
-#endif
        }
 
        return signal_usr1 || signal_usr2 || signal_term;