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

« back to all changes in this revision

Viewing changes to kernel_netlink.c

  • Committer: Package Import Robot
  • Author(s): Stéphane Glondu
  • Date: 2013-06-19 21:25:52 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20130619212552-gzarrkfhbicq00uj
Tags: 1.4.2-1
* New upstream release
* Use canonical URLs in Vcs-* fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
#include "util.h"
52
52
#include "interface.h"
53
53
 
54
 
int export_table = -1, import_table = -1;
 
54
#ifndef MAX_INTERFACES
 
55
#define MAX_INTERFACES 20
 
56
#endif
 
57
 
 
58
int export_table = -1, import_tables[MAX_IMPORT_TABLES], import_table_count = 0;
55
59
 
56
60
static int old_forwarding = -1;
57
61
static int old_ipv4_forwarding = -1;
58
62
static int old_accept_redirects = -1;
59
63
static int old_rp_filter = -1;
60
64
 
 
65
struct old_if {
 
66
    char *ifname;
 
67
    int rp_filter;
 
68
};
 
69
 
 
70
struct old_if old_if[MAX_INTERFACES];
 
71
int num_old_if = 0;
 
72
 
61
73
static int dgram_socket = -1;
62
74
 
63
75
#ifndef ARPHRD_ETHER
468
480
        if(export_table < 0)
469
481
            export_table = RT_TABLE_MAIN;
470
482
 
471
 
        if(import_table < 0)
472
 
            import_table = RT_TABLE_MAIN;
 
483
        if(import_table_count < 1)
 
484
            import_tables[import_table_count++] = RT_TABLE_MAIN;
473
485
 
474
486
        dgram_socket = socket(PF_INET, SOCK_DGRAM, 0);
475
487
        if(dgram_socket < 0)
614
626
    }
615
627
}
616
628
 
 
629
static int
 
630
get_old_if(const char *ifname)
 
631
{
 
632
    int i;
 
633
    for(i = 0; i < num_old_if; i++)
 
634
        if(strcmp(old_if->ifname, ifname) == 0)
 
635
            return i;
 
636
    if(num_old_if >= MAX_INTERFACES)
 
637
        return -1;
 
638
    old_if[num_old_if].ifname = strdup(ifname);
 
639
    if(old_if[num_old_if].ifname == NULL)
 
640
        return -1;
 
641
    old_if[num_old_if].rp_filter = -1;
 
642
    return num_old_if++;
 
643
}
 
644
 
617
645
int
618
646
kernel_setup_interface(int setup, const char *ifname, int ifindex)
619
647
{
 
648
    char buf[100];
 
649
    int i, rc;
 
650
 
 
651
    /* rp_filter has weird semantics: both all/rp_filter and ifname/rp_filter
 
652
       must be set to 0 for the rp_filter to be disabled.  Deal with it. */
 
653
 
 
654
    rc = snprintf(buf, 100, "/proc/sys/net/ipv4/conf/%s/rp_filter", ifname);
 
655
    if(rc < 0 || rc >= 100)
 
656
        return -1;
 
657
 
 
658
    i = get_old_if(ifname);
 
659
    if(setup) {
 
660
        if(i >= 0)
 
661
            old_if[i].rp_filter = read_proc(buf);
 
662
        else
 
663
            fprintf(stderr,
 
664
                    "Warning: cannot save old configuration for %s.\n",
 
665
                    ifname);
 
666
        rc = write_proc(buf, 0);
 
667
        if(rc < 0)
 
668
            return -1;
 
669
    } else {
 
670
        if(i >= 0 && old_if[i].rp_filter >= 0)
 
671
            rc = write_proc(buf, old_if[i].rp_filter);
 
672
        else
 
673
            rc = -1;
 
674
 
 
675
        if(rc < 0)
 
676
            fprintf(stderr,
 
677
                    "Warning: cannot restore old configuration for %s.\n",
 
678
                    ifname);
 
679
    }
 
680
 
620
681
    return 1;
621
682
}
622
683
 
1037
1098
    }
1038
1099
#undef COPY_ADDR
1039
1100
 
1040
 
    if(table != import_table)
1041
 
        return -1;
1042
 
 
1043
 
    return 0;
 
1101
    int i;
 
1102
    for(i = 0; i < import_table_count; i++)
 
1103
        if(table == import_tables[i])
 
1104
            return 0;
 
1105
    return -1;
1044
1106
}
1045
1107
 
1046
1108
static void