716
isbatman(const char *ifname, int ifindex)
721
rc = snprintf(buf, 256, "/sys/devices/virtual/net/%s/mesh", ifname);
722
if(rc < 0 || rc >= 256)
725
if(access(buf, F_OK) >= 0)
716
735
kernel_interface_wireless(const char *ifname, int ifindex)
721
740
struct ifreq req;
724
if(isbridge(ifname, ifindex) != 0) {
743
if(isbridge(ifname, ifindex) != 0 || isbatman(ifname, ifindex) != 0)
729
746
memset(&req, 0, sizeof(req));
730
747
strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
864
881
ipv4 = v4mapped(gate);
866
883
if(operation == ROUTE_MODIFY) {
868
884
if(newmetric == metric && memcmp(newgate, gate, 16) == 0 &&
869
885
newifindex == ifindex)
871
/* It is better to add the new route before removing the old
872
one, to avoid losing packets. However, if the old and new
873
priorities are equal, this only works if the kernel supports
874
ECMP. So we first try the "right" order, and fall back on
875
the "wrong" order if it fails with EEXIST. */
887
/* It would be better to add the new route before removing the
888
old one, to avoid losing packets. However, this causes
889
problems with non-multipath kernels, which sometimes
890
silently fail the request, causing "stuck" routes. Let's
891
stick with the naive approach, and hope that the window is
892
small enough to be negligible. */
893
kernel_route(ROUTE_FLUSH, dest, plen,
894
gate, ifindex, metric,
876
896
rc = kernel_route(ROUTE_ADD, dest, plen,
877
897
newgate, newifindex, newmetric,
887
kernel_route(ROUTE_FLUSH, dest, plen,
888
gate, ifindex, metric,
892
rc = kernel_route(ROUTE_ADD, dest, plen,
893
newgate, newifindex, newmetric,
898
/* In principle, we should try to re-install the flushed
899
route on failure to preserve. However, this should
900
hopefully not matter much in practice. */
902
/* Should we try to re-install the flushed route on failure?
903
Error handling is hard. */
1105
1106
if(rtm->rtm_src_len != 0)
1109
/* Ignore cached routes, advertised by some kernels (linux 3.x). */
1110
if(rtm->rtm_flags & RTM_F_CLONED)
1109
1114
current_route = &routes[*found];