Ticket #340: openvpn-route.diff

File openvpn-route.diff, 10.4 KB (added by bluhm, 8 years ago)

Patch rename struct route to route_base and include net/route.h

  • src/openvpn/route.c

    diff --git a/src/openvpn/route.c b/src/openvpn/route.c
    index 19b4bfe..5efc6cf 100644
    a b  
    4949#define METRIC_NOT_USED ((DWORD)-1)
    5050#endif
    5151
    52 static void delete_route (struct route *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es);
     52static void delete_route (struct route_base *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es);
    5353
    5454static void get_bypass_addresses (struct route_bypass *rb, const unsigned int flags);
    5555
    struct route_list * 
    150150new_route_list (const int max_routes, struct gc_arena *a)
    151151{
    152152  struct route_list *ret;
    153   ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_list, struct route, max_routes, a);
     153  ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_list, struct route_base, max_routes, a);
    154154  ret->capacity = max_routes;
    155155  return ret;
    156156}
    new_route_ipv6_list (const int max_routes, struct gc_arena *a) 
    165165}
    166166
    167167static const char *
    168 route_string (const struct route *r, struct gc_arena *gc)
     168route_string (const struct route_base *r, struct gc_arena *gc)
    169169{
    170170  struct buffer out = alloc_buf_gc (256, gc);
    171171  buf_printf (&out, "ROUTE network %s netmask %s gateway %s",
    is_special_addr (const char *addr_str) 
    267267}
    268268
    269269static bool
    270 init_route (struct route *r,
     270init_route (struct route_base *r,
    271271            struct addrinfo **network_list,
    272272            const struct route_option *ro,
    273273            const struct route_list *rl)
    void 
    484484clear_route_list (struct route_list *rl)
    485485{
    486486  const int capacity = rl->capacity;
    487   const size_t rl_size = array_mult_safe (sizeof(struct route), capacity, sizeof(struct route_list));
     487  const size_t rl_size = array_mult_safe (sizeof(struct route_base), capacity, sizeof(struct route_list));
    488488  memset(rl, 0, rl_size);
    489489  rl->capacity = capacity;
    490490}
    add_block_local_item (struct route_list *rl, 
    519519      && rl->rgi.gateway.netmask < 0xFFFFFFFF
    520520      && (rl->n)+2 <= rl->capacity)
    521521    {
    522       struct route r;
     522      struct route_base r;
    523523      unsigned int l2;
    524524
    525525      /* split a route into two smaller blocking routes, and direct them to target */
    init_route_list (struct route_list *rl, 
    649649    for (i = 0; i < opt->n; ++i)
    650650      {
    651651        struct addrinfo* netlist;
    652         struct route r;
     652        struct route_base r;
    653653
    654654        if (!init_route (&r,
    655655                         &netlist,
    add_route3 (in_addr_t network, 
    760760            const struct route_gateway_info *rgi,
    761761            const struct env_set *es)
    762762{
    763   struct route r;
     763  struct route_base r;
    764764  CLEAR (r);
    765765  r.flags = RT_DEFINED;
    766766  r.network = network;
    del_route3 (in_addr_t network, 
    778778            const struct route_gateway_info *rgi,
    779779            const struct env_set *es)
    780780{
    781   struct route r;
     781  struct route_base r;
    782782  CLEAR (r);
    783783  r.flags = RT_DEFINED|RT_ADDED;
    784784  r.network = network;
    add_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tun 
    10281028     
    10291029      for (i = 0; i < rl->n; ++i)
    10301030        {
    1031           struct route *r = &rl->routes[i];
     1031          struct route_base *r = &rl->routes[i];
    10321032          check_subnet_conflict (r->network, r->netmask, "route");
    10331033          if (flags & ROUTE_DELETE_FIRST)
    10341034            delete_route (r, tt, flags, &rl->rgi, es);
    delete_routes (struct route_list *rl, struct route_ipv6_list *rl6, 
    10601060      int i;
    10611061      for (i = rl->n - 1; i >= 0; --i)
    10621062        {
    1063           struct route * r = &rl->routes[i];
     1063          struct route_base * r = &rl->routes[i];
    10641064          delete_route (r, tt, flags, &rl->rgi, es);
    10651065        }
    10661066      rl->iflags &= ~RL_ROUTES_ADDED;
    print_default_gateway(const int msglevel, const struct route_gateway_info *rgi) 
    11541154#endif
    11551155
    11561156static void
    1157 print_route (const struct route *r, int level)
     1157print_route (const struct route_base *r, int level)
    11581158{
    11591159  struct gc_arena gc = gc_new ();
    11601160  if (r->flags & RT_DEFINED)
    print_routes (const struct route_list *rl, int level) 
    11711171}
    11721172
    11731173static void
    1174 setenv_route (struct env_set *es, const struct route *r, int i)
     1174setenv_route (struct env_set *es, const struct route_base *r, int i)
    11751175{
    11761176  struct gc_arena gc = gc_new ();
    11771177  if (r->flags & RT_DEFINED)
    is_on_link (const int is_local_route, const unsigned int flags, const struct rou 
    12881288}
    12891289
    12901290void
    1291 add_route (struct route *r,
     1291add_route (struct route_base *r,
    12921292           const struct tuntap *tt,
    12931293           unsigned int flags,
    12941294           const struct route_gateway_info *rgi, /* may be NULL */
    add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int fla 
    17411741}
    17421742
    17431743static void
    1744 delete_route (struct route *r,
     1744delete_route (struct route_base *r,
    17451745              const struct tuntap *tt,
    17461746              unsigned int flags,
    17471747              const struct route_gateway_info *rgi,
    get_default_gateway (struct route_gateway_info *rgi) 
    22462246}
    22472247
    22482248static DWORD
    2249 windows_route_find_if_index (const struct route *r, const struct tuntap *tt)
     2249windows_route_find_if_index (const struct route_base *r, const struct tuntap *tt)
    22502250{
    22512251  struct gc_arena gc = gc_new ();
    22522252  DWORD ret = TUN_ADAPTER_INDEX_INVALID;
    windows_route_find_if_index (const struct route *r, const struct tuntap *tt) 
    22912291}
    22922292
    22932293bool
    2294 add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_index)
     2294add_route_ipapi (const struct route_base *r, const struct tuntap *tt, DWORD adapter_index)
    22952295{
    22962296  struct gc_arena gc = gc_new ();
    22972297  bool ret = false;
    add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_i 
    23652365}
    23662366
    23672367bool
    2368 del_route_ipapi (const struct route *r, const struct tuntap *tt)
     2368del_route_ipapi (const struct route_base *r, const struct tuntap *tt)
    23692369{
    23702370  struct gc_arena gc = gc_new ();
    23712371  bool ret = false;
    get_default_gateway (struct route_gateway_info *rgi) 
    29762976#include <sys/types.h>
    29772977#include <sys/socket.h>
    29782978#include <netinet/in.h>
    2979 
    2980 /* all of this is taken from <net/route.h> in OpenBSD 3.6 */
    2981 #define RTA_DST         0x1     /* destination sockaddr present */
    2982 #define RTA_GATEWAY     0x2     /* gateway sockaddr present */
    2983 #define RTA_NETMASK     0x4     /* netmask sockaddr present */
    2984 
    2985 #define RTM_GET         0x4     /* Report Metrics */
    2986 
    2987 #define RTM_VERSION     3       /* Up the ante and ignore older versions */
    2988 
    2989 #define RTF_UP          0x1             /* route usable */
    2990 #define RTF_GATEWAY     0x2             /* destination is a gateway */
    2991 
    2992 /*
    2993  * Huge version for userland compatibility.
    2994  */
    2995 struct rt_metrics {
    2996         u_long  rmx_locks;      /* Kernel must leave these values alone */
    2997         u_long  rmx_mtu;        /* MTU for this path */
    2998         u_long  rmx_hopcount;   /* max hops expected */
    2999         u_long  rmx_expire;     /* lifetime for route, e.g. redirect */
    3000         u_long  rmx_recvpipe;   /* inbound delay-bandwidth product */
    3001         u_long  rmx_sendpipe;   /* outbound delay-bandwidth product */
    3002         u_long  rmx_ssthresh;   /* outbound gateway buffer limit */
    3003         u_long  rmx_rtt;        /* estimated round trip time */
    3004         u_long  rmx_rttvar;     /* estimated rtt variance */
    3005         u_long  rmx_pksent;     /* packets sent using this route */
    3006 };
    3007 
    3008 /*
    3009  * Structures for routing messages.
    3010  */
    3011 struct rt_msghdr {
    3012         u_short rtm_msglen;     /* to skip over non-understood messages */
    3013         u_char  rtm_version;    /* future binary compatibility */
    3014         u_char  rtm_type;       /* message type */
    3015         u_short rtm_index;      /* index for associated ifp */
    3016         int     rtm_flags;      /* flags, incl. kern & message, e.g. DONE */
    3017         int     rtm_addrs;      /* bitmask identifying sockaddrs in msg */
    3018         pid_t   rtm_pid;        /* identify sender */
    3019         int     rtm_seq;        /* for sender to identify action */
    3020         int     rtm_errno;      /* why failed */
    3021         int     rtm_use;        /* from rtentry */
    3022         u_long  rtm_inits;      /* which metrics we are initializing */
    3023         struct  rt_metrics rtm_rmx; /* metrics themselves */
    3024 };
     2979#include <net/route.h>
    30252980
    30262981struct {
    30272982  struct rt_msghdr m_rtm;
  • src/openvpn/route.h

    diff --git a/src/openvpn/route.h b/src/openvpn/route.h
    index a40de32..f12b942 100644
    a b struct route_ipv6_option_list { 
    110110  struct route_ipv6_option routes_ipv6[EMPTY_ARRAY_SIZE];
    111111};
    112112
    113 struct route {
     113struct route_base {
    114114# define RT_DEFINED        (1<<0)
    115115# define RT_ADDED          (1<<1)
    116116# define RT_METRIC_DEFINED (1<<2)
    struct route_list { 
    190190  unsigned int flags;     /* RG_x flags */
    191191  int capacity;
    192192  int n;
    193   struct route routes[EMPTY_ARRAY_SIZE];
     193  struct route_base routes[EMPTY_ARRAY_SIZE];
    194194};
    195195
    196196#if P2MP
    struct route_ipv6_list *new_route_ipv6_list (const int max_routes, struct gc_are 
    223223void add_route_ipv6 (struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
    224224void delete_route_ipv6 (const struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
    225225
    226 void add_route (struct route *r,
     226void add_route (struct route_base *r,
    227227                const struct tuntap *tt,
    228228                unsigned int flags,
    229229                const struct route_gateway_info *rgi,
    void print_routes (const struct route_list *rl, int level); 
    301301
    302302void show_routes (int msglev);
    303303bool test_routes (const struct route_list *rl, const struct tuntap *tt);
    304 bool add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_index);
    305 bool del_route_ipapi (const struct route *r, const struct tuntap *tt);
     304bool add_route_ipapi (const struct route_base *r, const struct tuntap *tt, DWORD adapter_index);
     305bool del_route_ipapi (const struct route_base *r, const struct tuntap *tt);
    306306
    307307#else
    308308static inline bool test_routes (const struct route_list *rl, const struct tuntap *tt) { return true; }
  • src/openvpn/tun.c

    diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
    index 86a43f2..ea7594b 100644
    a b do_ifconfig (struct tuntap *tt, 
    902902      if (!tun && tt->topology == TOP_SUBNET)
    903903        {
    904904          /* Add a network route for the local tun interface */
    905           struct route r;
     905          struct route_base r;
    906906          CLEAR (r);     
    907907          r.flags = RT_DEFINED | RT_METRIC_DEFINED;
    908908          r.network = tt->local & tt->remote_netmask;
    do_ifconfig (struct tuntap *tt, 
    10991099      /* Add a network route for the local tun interface */
    11001100      if (!tun && tt->topology == TOP_SUBNET)
    11011101        {
    1102           struct route r;
     1102          struct route_base r;
    11031103          CLEAR (r);
    11041104          r.flags = RT_DEFINED;
    11051105          r.network = tt->local & tt->remote_netmask;
    do_ifconfig (struct tuntap *tt, 
    11651165        /* Add a network route for the local tun interface */
    11661166      if (!tun && tt->topology == TOP_SUBNET)
    11671167        {
    1168           struct route r;
     1168          struct route_base r;
    11691169          CLEAR (r);
    11701170          r.flags = RT_DEFINED;
    11711171          r.network = tt->local & tt->remote_netmask;