~ubuntu-branches/ubuntu/utopic/babeld/utopic-proposed

« back to all changes in this revision

Viewing changes to kernel_netlink.c

  • Committer: Package Import Robot
  • Author(s): Stéphane Glondu
  • Date: 2013-05-26 21:03:16 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130526210316-6yd2mu09pctqo36y
Tags: 1.4.1-1
* New upstream release (Closes: #709919)
* Add logrotate support (Closes: #659618)
* Switch debian/copyright to format version 1.0
* Bump Standards-Version to 3.9.4
* Bump debhelper compat level to 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
568
568
 
569
569
        if(old_rp_filter >= 0) {
570
570
            rc = write_proc("/proc/sys/net/ipv4/conf/all/rp_filter",
571
 
                            old_accept_redirects);
 
571
                            old_rp_filter);
572
572
            if(rc < 0) {
573
573
                perror("Couldn't write rp_filter knob.\n");
574
574
                return -1;
712
712
    return 0;
713
713
}
714
714
 
 
715
static int
 
716
isbatman(const char *ifname, int ifindex)
 
717
{
 
718
    char buf[256];
 
719
    int rc;
 
720
 
 
721
    rc = snprintf(buf, 256, "/sys/devices/virtual/net/%s/mesh", ifname);
 
722
    if(rc < 0 || rc >= 256)
 
723
        return -1;
 
724
 
 
725
    if(access(buf, F_OK) >= 0)
 
726
        return 1;
 
727
 
 
728
    if(errno != ENOENT)
 
729
        return -1;
 
730
 
 
731
    return 0;
 
732
}
 
733
 
715
734
int
716
735
kernel_interface_wireless(const char *ifname, int ifindex)
717
736
{
721
740
    struct ifreq req;
722
741
    int rc;
723
742
 
724
 
    if(isbridge(ifname, ifindex) != 0) {
725
 
        /* Give up. */
 
743
    if(isbridge(ifname, ifindex) != 0 || isbatman(ifname, ifindex) != 0)
726
744
        return -1;
727
 
    }
728
745
 
729
746
    memset(&req, 0, sizeof(req));
730
747
    strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
864
881
    ipv4 = v4mapped(gate);
865
882
 
866
883
    if(operation == ROUTE_MODIFY) {
867
 
        int added;
868
884
        if(newmetric == metric && memcmp(newgate, gate, 16) == 0 &&
869
885
           newifindex == ifindex)
870
886
            return 0;
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,
 
895
                     NULL, 0, 0);
876
896
        rc = kernel_route(ROUTE_ADD, dest, plen,
877
897
                          newgate, newifindex, newmetric,
878
898
                          NULL, 0, 0);
879
899
        if(rc < 0) {
880
 
            if(errno != EEXIST)
881
 
                return rc;
882
 
            added = 0;
883
 
        } else {
884
 
            added = 1;
885
 
        }
886
 
 
887
 
        kernel_route(ROUTE_FLUSH, dest, plen,
888
 
                     gate, ifindex, metric,
889
 
                     NULL, 0, 0);
890
 
 
891
 
        if(!added) {
892
 
            rc = kernel_route(ROUTE_ADD, dest, plen,
893
 
                              newgate, newifindex, newmetric,
894
 
                              NULL, 0, 0);
895
 
            if(rc < 0) {
896
 
                if(errno == EEXIST)
897
 
                    rc = 1;
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. */
901
 
            }
902
 
        }
903
 
 
 
900
            if(errno == EEXIST)
 
901
                rc = 1;
 
902
            /* Should we try to re-install the flushed route on failure?
 
903
               Error handling is hard. */
 
904
        }
904
905
        return rc;
905
906
    }
906
907
 
1105
1106
    if(rtm->rtm_src_len != 0)
1106
1107
        return 0;
1107
1108
 
 
1109
    /* Ignore cached routes, advertised by some kernels (linux 3.x). */
 
1110
    if(rtm->rtm_flags & RTM_F_CLONED)
 
1111
        return 0;
 
1112
 
1108
1113
    if(data)
1109
1114
        current_route = &routes[*found];
1110
1115
    else