On 23/08/17 07:30, Antonio Quartulli wrote: > This patch does not introduce any functional change. > > The code in route.c seems to have been written in different > periods by different people, without sticking to a clear > codestyle. For this reason the code in this file in not > consistent at all. > > Clean it up by: > - removing spaces from function invocations > - cutting line longer than 80 chars (where possible) > - moving function arguments on the same line when there is enough space > - adding empty line between var declarations and code > - adding empty line between code and final return > - adding empty line to make the code less sticky and easier to parse > > Signed-off-by: Antonio Quartulli <a...@unstable.cc> > --- > > Yes, this is a quite big patch. However, since we are planning a big > restructuring of the route.c file, it is better to take care of the > style in a separate patch (this) so that later we don't need to mixup cleanups > and refactoring. > > Note that this patch is based on master plus the following patches: > > - ensure function declarations are compiled with their definitions > - fix a couple of typ0s in comments and strings > - route: avoid definition of unused variables in certain configurations > - convert *_inline attributes to bool > - reformatting: fix style in crypto*.{c, h} > - Allow learning iroutes with network made up of all 0s (only if netbits < 8) > - ifconfig-ipv6(-push): allow using hostnames > > > Applying this patch without the above, might lead to screams, > natural disasters and endless nightmares.
I got it applying quite nicely (working my way through more patches now). And yes, I like that we clean up the coding style further in this file. But unfortunately, I'll have to say NAK in this round. - Many places you replace spaces with tabs. - There are several scenarios where our uncrustify config actually improves your patch further (see the attachment). - And the contradictions like the ones below > -static void delete_route(struct route_ipv4 *r, const struct tuntap *tt, > unsigned int flags, const struct route_gateway_info *rgi, const struct > env_set *es); > +static void delete_route(struct route_ipv4 *r, const struct tuntap *tt, > + unsigned int flags, > + const struct route_gateway_info *rgi, > + const struct env_set *es); vs > static void > -delete_route(struct route_ipv4 *r, > - const struct tuntap *tt, > - unsigned int flags, > - const struct route_gateway_info *rgi, > - const struct env_set *es) > +delete_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int > flags, > + const struct route_gateway_info *rgi, const struct env_set *es) I think the change you do in the former one is also more readable than squeezing everything into as few lines as possible, especially when there's lots of arguments. Our uncrustify config doesn't touch these details of function declarations, as tun.c and route.c is fairly extreme in variations here. So we let that pass on the reformatting patch before the v2.4 release, to take care of them manually, as we didn't spend much extra time looking at more tweaks for uncrustify to make the result readable. But I'm not sure we documented our preferences on function declarations, I don't recall that now. Even though we are not united in the use of uncrustify after the reformatting patches we did in December, I think it makes sense to at least double check what uncrustify would change and consider those. The lesser the gap is to that result, the easier it will be to have a consistent coding style over the complete code base. For reference, the uncrustify command line I used was: $ uncrustify -c dev-tools/uncrustify.conf \ --no-backup -l C -p debug.uncr \ src/openvpn/route.c -- kind regards, David Sommerseth OpenVPN Technologies, Inc
diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 605c367c..3ae75b1b 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -57,20 +57,20 @@ static bool add_route_service(const struct route_ipv4 *, const struct tuntap *); static bool del_route_service(const struct route_ipv4 *, const struct tuntap *); static bool add_route_ipv6_service(const struct route_ipv6 *, - const struct tuntap *); + const struct tuntap *); static bool del_route_ipv6_service(const struct route_ipv6 *, - const struct tuntap *); + const struct tuntap *); #endif static void delete_route(struct route_ipv4 *r, const struct tuntap *tt, - unsigned int flags, - const struct route_gateway_info *rgi, - const struct env_set *es); + unsigned int flags, + const struct route_gateway_info *rgi, + const struct env_set *es); static void get_bypass_addresses(struct route_bypass *rb, - const unsigned int flags); + const unsigned int flags); #ifdef ENABLE_DEBUG @@ -154,7 +154,7 @@ clone_route_option_list(const struct route_option_list *src, struct gc_arena *a) struct route_ipv6_option_list * clone_route_ipv6_option_list(const struct route_ipv6_option_list *src, - struct gc_arena *a) + struct gc_arena *a) { struct route_ipv6_option_list *ret; @@ -166,7 +166,7 @@ clone_route_ipv6_option_list(const struct route_ipv6_option_list *src, void copy_route_option_list(struct route_option_list *dest, - const struct route_option_list *src, struct gc_arena *a) + const struct route_option_list *src, struct gc_arena *a) { *dest = *src; dest->gc = a; @@ -216,7 +216,7 @@ is_route_parm_defined(const char *parm) static void setenv_route_addr(struct env_set *es, const char *key, const in_addr_t addr, - int i) + int i) { struct gc_arena gc = gc_new(); struct buffer name = alloc_buf_gc(256, &gc); @@ -343,7 +343,7 @@ init_route(struct route_ipv4 *r, struct addrinfo **network_list, * like gw. getaddrinfo is called to convert a a addrinfo struct */ if (get_special_addr(rl, ro->network, (in_addr_t *) &special.s_addr, - &status)) + &status)) { special.s_addr = htonl(special.s_addr); ret = openvpn_getaddrinfo(0, inet_ntoa(special), NULL, 0, NULL, @@ -353,7 +353,7 @@ init_route(struct route_ipv4 *r, struct addrinfo **network_list, { ret = openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL, ro->network, NULL, 0, NULL, AF_INET, - network_list); + network_list); } status = (ret == 0); @@ -368,7 +368,7 @@ init_route(struct route_ipv4 *r, struct addrinfo **network_list, if (is_route_parm_defined(ro->netmask)) { r->netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_WARN_ON_SIGNAL, - ro->netmask, 0, &status, NULL); + ro->netmask, 0, &status, NULL); if (!status) { goto fail; @@ -385,9 +385,9 @@ init_route(struct route_ipv4 *r, struct addrinfo **network_list, { if (!get_special_addr(rl, ro->gateway, &r->gateway, &status)) { - r->gateway = getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDER | - GETADDR_WARN_ON_SIGNAL, ro->gateway, 0, - &status, NULL); + r->gateway = getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDER + |GETADDR_WARN_ON_SIGNAL, ro->gateway, 0, + &status, NULL); } if (!status) { @@ -456,7 +456,7 @@ init_route_ipv6(struct route_ipv6 *r6, if (inet_pton(AF_INET6, r6o->gateway, &r6->gateway) != 1) { msg(M_WARN, PACKAGE_NAME "ROUTE6: cannot parse gateway spec '%s'", - r6o->gateway ); + r6o->gateway ); } } else if (rl6->spec_flags & RTSA_REMOTE_ENDPOINT) @@ -501,8 +501,8 @@ fail: void add_route_to_option_list(struct route_option_list *l, const char *network, - const char *netmask, const char *gateway, - const char *metric) + const char *netmask, const char *gateway, + const char *metric) { struct route_option *ro; ALLOC_OBJ_GC(ro, struct route_option, l->gc); @@ -517,8 +517,8 @@ add_route_to_option_list(struct route_option_list *l, const char *network, void add_route_ipv6_to_option_list(struct route_ipv6_option_list *l, - const char *prefix, const char *gateway, - const char *metric) + const char *prefix, const char *gateway, + const char *metric) { struct route_ipv6_option *ro; @@ -546,7 +546,7 @@ clear_route_ipv6_list(struct route_ipv6_list *rl6) void route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es, - const in_addr_t addr) + const in_addr_t addr) { ASSERT(rl); rl->spec.remote_endpoint = addr; @@ -561,8 +561,8 @@ add_block_local_item(struct route_list *rl, { const int rgi_needed = (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); - if (((rl->rgi.flags & rgi_needed) == rgi_needed) && - (rl->rgi.gateway.netmask < 0xFFFFFFFF)) + if (((rl->rgi.flags & rgi_needed) == rgi_needed) + && (rl->rgi.gateway.netmask < 0xFFFFFFFF)) { struct route_ipv4 *r1, *r2; unsigned int l2; @@ -591,10 +591,10 @@ add_block_local(struct route_list *rl) { const int rgi_needed = (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); - if ((rl->flags & RG_BLOCK_LOCAL) && - ((rl->rgi.flags & rgi_needed) == rgi_needed) && - (rl->spec.flags & RTSA_REMOTE_ENDPOINT) && - (rl->spec.remote_host_local != TLA_LOCAL)) + if ((rl->flags & RG_BLOCK_LOCAL) + && ((rl->rgi.flags & rgi_needed) == rgi_needed) + && (rl->spec.flags & RTSA_REMOTE_ENDPOINT) + && (rl->spec.remote_host_local != TLA_LOCAL)) { size_t i; @@ -610,8 +610,8 @@ add_block_local(struct route_list *rl) for (i = 0; i < rl->rgi.n_addrs; ++i) { const struct route_gateway_address *gwa = &rl->rgi.addrs[i]; - in_addr_t net1 = rl->rgi.gateway.addr & rl->rgi.gateway.netmask; - in_addr_t net2 = gwa->addr & gwa->netmask; + in_addr_t net1 = rl->rgi.gateway.addr & rl->rgi.gateway.netmask; + in_addr_t net2 = gwa->addr & gwa->netmask; /* omit the add/subnet in &rl->rgi which we processed above */ if ((net1 != net2) || (rl->rgi.gateway.netmask != gwa->netmask)) @@ -624,8 +624,8 @@ add_block_local(struct route_list *rl) bool init_route_list(struct route_list *rl, const struct route_option_list *opt, - const char *remote_endpoint, int default_metric, - in_addr_t remote_host, struct env_set *es) + const char *remote_endpoint, int default_metric, + in_addr_t remote_host, struct env_set *es) { struct gc_arena gc = gc_new(); bool ret = true; @@ -667,10 +667,10 @@ init_route_list(struct route_list *rl, const struct route_option_list *opt, if (is_route_parm_defined(remote_endpoint)) { bool defined = false; - rl->spec.remote_endpoint = getaddr(GETADDR_RESOLVE | - GETADDR_HOST_ORDER | - GETADDR_WARN_ON_SIGNAL, - remote_endpoint, 0, &defined, NULL); + rl->spec.remote_endpoint = getaddr(GETADDR_RESOLVE + |GETADDR_HOST_ORDER + |GETADDR_WARN_ON_SIGNAL, + remote_endpoint, 0, &defined, NULL); if (defined) { @@ -711,12 +711,12 @@ init_route_list(struct route_list *rl, const struct route_option_list *opt, struct addrinfo *curele; for (curele = netlist; curele; curele = curele->ai_next) { - struct sockaddr_in *ai_addr; + struct sockaddr_in *ai_addr; struct route_ipv4 *new; ALLOC_OBJ_GC(new, struct route_ipv4, &rl->gc); *new = r; - ai_addr = (struct sockaddr_in *)curele->ai_addr; + ai_addr = (struct sockaddr_in *)curele->ai_addr; new->network = ntohl(ai_addr->sin_addr.s_addr); new->next = rl->routes; rl->routes = new; @@ -775,9 +775,9 @@ route_ipv6_match_host(const struct route_ipv6 *r6, const struct in6_addr *host) bool init_route_ipv6_list(struct route_ipv6_list *rl6, - const struct route_ipv6_option_list *opt6, - const char *remote_endpoint, int default_metric, - const struct in6_addr *remote_host_ipv6, + const struct route_ipv6_option_list *opt6, + const char *remote_endpoint, int default_metric, + const struct in6_addr *remote_host_ipv6, struct env_set *es) { struct gc_arena gc = gc_new(); @@ -807,7 +807,7 @@ init_route_ipv6_list(struct route_ipv6_list *rl6, if (rl6->rgi6.flags & RGI_ADDR_DEFINED) { setenv_str(es, "net_gateway_ipv6", - print_in6_addr(rl6->rgi6.gateway.addr_ipv6, 0, &gc)); + print_in6_addr(rl6->rgi6.gateway.addr_ipv6, 0, &gc)); #if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL) print_default_gateway(D_ROUTE, NULL, &rl6->rgi6); #endif @@ -820,14 +820,14 @@ init_route_ipv6_list(struct route_ipv6_list *rl6, if (is_route_parm_defined(remote_endpoint)) { if (inet_pton(AF_INET6, remote_endpoint, - &rl6->remote_endpoint_ipv6) == 1) + &rl6->remote_endpoint_ipv6) == 1) { rl6->spec_flags |= RTSA_REMOTE_ENDPOINT; } else { msg(M_WARN, PACKAGE_NAME " ROUTE: failed to parse/resolve VPN endpoint: %s", - remote_endpoint); + remote_endpoint); ret = false; } } @@ -859,8 +859,8 @@ init_route_ipv6_list(struct route_ipv6_list *rl6, * avoiding routing loops, so ignore this part and let * need_remote_ipv6_route always evaluate to false */ - if (remote_host_ipv6 && - route_ipv6_match_host(r6, remote_host_ipv6)) + if (remote_host_ipv6 + && route_ipv6_match_host(r6, remote_host_ipv6)) { need_remote_ipv6_route = true; msg(D_ROUTE, "ROUTE6: %s/%d overlaps IPv6 remote %s, adding host route to VPN endpoint", @@ -875,7 +875,7 @@ init_route_ipv6_list(struct route_ipv6_list *rl6, /* add VPN server host route if needed */ if (need_remote_ipv6_route) { - int defined = RGI_ADDR_DEFINED | RGI_IFACE_DEFINED; + int defined = RGI_ADDR_DEFINED | RGI_IFACE_DEFINED; if ((rl6->rgi6.flags & defined) == defined) { @@ -912,8 +912,8 @@ init_route_ipv6_list(struct route_ipv6_list *rl6, static void add_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, - const struct tuntap *tt, unsigned int flags, - const struct route_gateway_info *rgi, const struct env_set *es) + const struct tuntap *tt, unsigned int flags, + const struct route_gateway_info *rgi, const struct env_set *es) { struct route_ipv4 r; @@ -927,8 +927,8 @@ add_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, static void del_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, - const struct tuntap *tt, unsigned int flags, - const struct route_gateway_info *rgi, const struct env_set *es) + const struct tuntap *tt, unsigned int flags, + const struct route_gateway_info *rgi, const struct env_set *es) { struct route_ipv4 r; @@ -942,9 +942,9 @@ del_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, static void add_bypass_routes(struct route_bypass *rb, in_addr_t gateway, - const struct tuntap *tt, unsigned int flags, + const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, - const struct env_set *es) + const struct env_set *es) { int i; @@ -953,16 +953,16 @@ add_bypass_routes(struct route_bypass *rb, in_addr_t gateway, if (rb->bypass[i]) { add_route3(rb->bypass[i], IPV4_NETMASK_HOST, gateway, tt, - flags | ROUTE_REF_GW, rgi, es); + flags | ROUTE_REF_GW, rgi, es); } } } static void del_bypass_routes(struct route_bypass *rb, in_addr_t gateway, - const struct tuntap *tt, unsigned int flags, - const struct route_gateway_info *rgi, - const struct env_set *es) + const struct tuntap *tt, unsigned int flags, + const struct route_gateway_info *rgi, + const struct env_set *es) { int i; @@ -971,14 +971,14 @@ del_bypass_routes(struct route_bypass *rb, in_addr_t gateway, if (rb->bypass[i]) { del_route3(rb->bypass[i], IPV4_NETMASK_HOST, gateway, tt, - flags | ROUTE_REF_GW, rgi, es); + flags | ROUTE_REF_GW, rgi, es); } } } static void redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, - unsigned int flags, const struct env_set *es) + unsigned int flags, const struct env_set *es) { const char err[] = "NOTE: unable to redirect default gateway --"; @@ -986,22 +986,22 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, { bool local = rl->flags & RG_LOCAL; - if (!(rl->spec.flags & RTSA_REMOTE_ENDPOINT) && - (rl->flags & RG_REROUTE_GW)) + if (!(rl->spec.flags & RTSA_REMOTE_ENDPOINT) + && (rl->flags & RG_REROUTE_GW)) { msg(M_WARN, "%s VPN gateway parameter (--route-gateway or --ifconfig) is missing", - err); + err); } /* * check if a default route is defined, unless: * - we are connecting to a remote host in our network * - we are connecting to a non-IPv4 remote host (i.e. we use IPv6) */ - else if (!(rl->rgi.flags & RGI_ADDR_DEFINED) && !local && - (rl->spec.remote_host != IPV4_INVALID_ADDR)) + else if (!(rl->rgi.flags & RGI_ADDR_DEFINED) && !local + && (rl->spec.remote_host != IPV4_INVALID_ADDR)) { msg(M_WARN, "%s Cannot read current default gateway from system", - err); + err); } else if (!(rl->spec.flags & RTSA_REMOTE_HOST)) { @@ -1033,7 +1033,7 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, if (rl->spec.remote_host != IPV4_INVALID_ADDR) { add_route3(rl->spec.remote_host, IPV4_NETMASK_HOST, - rl->rgi.gateway.addr, tt, flags | ROUTE_REF_GW, + rl->rgi.gateway.addr, tt, flags | ROUTE_REF_GW, &rl->rgi, es); rl->iflags |= RL_DID_LOCAL; } @@ -1046,7 +1046,7 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, /* route DHCP/DNS server traffic through original default gateway */ add_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flags, - &rl->rgi, es); + &rl->rgi, es); if (rl->flags & RG_REROUTE_GW) { @@ -1471,11 +1471,11 @@ local_route(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct route_gateway_info *rgi) { /* set LR_MATCH on local host routes */ - const int rgi_needed = (RGI_ADDR_DEFINED | RGI_NETMASK_DEFINED | - RGI_IFACE_DEFINED); + const int rgi_needed = (RGI_ADDR_DEFINED | RGI_NETMASK_DEFINED + |RGI_IFACE_DEFINED); - if (rgi && ((rgi->flags & rgi_needed) == rgi_needed) && - (gateway == rgi->gateway.addr) && (netmask == 0xFFFFFFFF)) + if (rgi && ((rgi->flags & rgi_needed) == rgi_needed) + && (gateway == rgi->gateway.addr) && (netmask == 0xFFFFFFFF)) { if (((network ^ rgi->gateway.addr) & rgi->gateway.netmask) == 0) { @@ -1508,8 +1508,8 @@ static inline bool is_on_link(const int is_local_route, const unsigned int flags, const struct route_gateway_info *rgi) { - return rgi && ((is_local_route == LR_MATCH) || - ((flags & ROUTE_REF_GW) && (rgi->flags & RGI_ON_LINK))); + return rgi && ((is_local_route == LR_MATCH) + || ((flags & ROUTE_REF_GW) && (rgi->flags & RGI_ON_LINK))); } void @@ -1857,16 +1857,16 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, network = print_in6_addr(r6->network, 0, &gc); gateway = print_in6_addr(r6->gateway, 0, &gc); -#if defined(TARGET_DARWIN) || \ - defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || \ - defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) +#if defined(TARGET_DARWIN) \ + || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ + || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) /* the BSD platforms cannot specify gateway and interface independently, * but for link-local destinations, we MUST specify the interface, so * we build a combined "$gateway%$interface" gateway string */ - if (r6->iface != NULL && gateway_needed && - IN6_IS_ADDR_LINKLOCAL(&r6->gateway)) /* fe80::...%intf */ + if (r6->iface != NULL && gateway_needed + && IN6_IS_ADDR_LINKLOCAL(&r6->gateway)) /* fe80::...%intf */ { int len = strlen(gateway) + 1 + strlen(r6->iface) + 1; char *tmp = gc_malloc( len, true, &gc ); @@ -1890,8 +1890,8 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, * interfaces. OTOH, on "tap" interface, we must always set the * gateway unless the route is to be an on-link network */ - if ((tt->type == DEV_TYPE_TAP) && - !((r6->flags & RT_METRIC_DEFINED) && (r6->metric == 0))) + if ((tt->type == DEV_TYPE_TAP) + && !((r6->flags & RT_METRIC_DEFINED) && (r6->metric == 0))) { gateway_needed = true; } @@ -2303,16 +2303,16 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, network = print_in6_addr(r6->network, 0, &gc); gateway = print_in6_addr(r6->gateway, 0, &gc); -#if defined(TARGET_DARWIN) || \ - defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || \ - defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) +#if defined(TARGET_DARWIN) \ + || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ + || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) /* the BSD platforms cannot specify gateway and interface independently, * but for link-local destinations, we MUST specify the interface, so * we build a combined "$gateway%$interface" gateway string */ - if ((r6->iface != NULL) && gateway_needed && - IN6_IS_ADDR_LINKLOCAL(&r6->gateway)) /* fe80::...%intf */ + if ((r6->iface != NULL) && gateway_needed + && IN6_IS_ADDR_LINKLOCAL(&r6->gateway)) /* fe80::...%intf */ { int len = strlen(gateway) + 1 + strlen(r6->iface) + 1; char *tmp = gc_malloc(len, true, &gc); @@ -2327,8 +2327,8 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, /* if we used a gateway on "add route", we also need to specify it on * delete, otherwise some OSes will refuse to delete the route */ - if ((tt->type == DEV_TYPE_TAP) && - !((r6->flags & RT_METRIC_DEFINED) && (r6->metric == 0))) + if ((tt->type == DEV_TYPE_TAP) + && !((r6->flags & RT_METRIC_DEFINED) && (r6->metric == 0))) { gateway_needed = true; } @@ -2597,8 +2597,8 @@ test_routes(const struct route_list *rl, const struct tuntap *tt) r->gateway); } - if ((rl->flags & RG_ENABLE) && - (rl->spec.flags & RTSA_REMOTE_ENDPOINT)) + if ((rl->flags & RG_ENABLE) + && (rl->spec.flags & RTSA_REMOTE_ENDPOINT)) { test_route_helper(&ret, &count, &good, &ambig, adapters, rl->spec.remote_endpoint); @@ -2818,12 +2818,18 @@ add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD if_index; if (adapter_index == TUN_ADAPTER_INDEX_INVALID) + { if_index = windows_route_find_if_index(r, tt); + } else + { if_index = adapter_index; + } if (if_index == TUN_ADAPTER_INDEX_INVALID) + { return false; + } gc = gc_new(); MIB_IPFORWARDROW fr; @@ -2914,7 +2920,9 @@ del_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt) const DWORD if_index = windows_route_find_if_index(r, tt); if (if_index == TUN_ADAPTER_INDEX_INVALID) + { return false; + } gc = gc_new(); MIB_IPFORWARDROW fr; @@ -2953,8 +2961,8 @@ do_route_service(const bool add, const route_message_t *rt, const size_t size, ack_message_t ack; struct gc_arena gc = gc_new(); - if (!WriteFile(pipe, rt, size, &len, NULL) || - !ReadFile(pipe, &ack, sizeof(ack), &len, NULL)) + if (!WriteFile(pipe, rt, size, &len, NULL) + || !ReadFile(pipe, &ack, sizeof(ack), &len, NULL)) { msg(M_WARN, "ROUTE: could not talk to service: %s [%lu]", strerror_win32(GetLastError(), &gc), GetLastError()); @@ -3040,8 +3048,8 @@ do_route_ipv6_service(const bool add, const struct route_ipv6 *r, * The tapdrvr knows about it and will answer neighbor discovery packets. * (only do this for routes actually using the tun/tap device) */ - if ((tt->type == DEV_TYPE_TUN) && - (msg.iface.index == tt->adapter_index)) + if ((tt->type == DEV_TYPE_TUN) + && (msg.iface.index == tt->adapter_index)) { inet_pton(AF_INET6, "fe80::8", &msg.gateway.ipv6); } @@ -3232,7 +3240,9 @@ get_default_gateway(struct route_gateway_info *rgi) for (ifr = ifc.ifc_req; ifr < ifend; ifr++) { if (ifr->ifr_addr.sa_family != AF_INET) + { continue; + } /* get interface addr */ struct sockaddr_in *sk_addr = (struct sockaddr_in *)&ifr->ifr_addr; @@ -3254,22 +3264,22 @@ get_default_gateway(struct route_gateway_info *rgi) if (rgi->flags & RGI_ON_LINK) { /* check that interface name of current interface - * matches interface name of best default route */ + * matches interface name of best default route */ if (strcmp(ifreq.ifr_name, best_name)) { continue; } #if 0 /* if point-to-point link, use remote addr as route gateway */ - if ((ifreq.ifr_flags & IFF_POINTOPOINT) && - (ioctl(sd, SIOCGIFDSTADDR, &ifreq) >= 0)) + if ((ifreq.ifr_flags & IFF_POINTOPOINT) + && (ioctl(sd, SIOCGIFDSTADDR, &ifreq) >= 0)) { rgi->gateway.addr = ntohl((addr->sin_addr.s_addr); - if (rgi->gateway.addr) + if (rgi->gateway.addr) { rgi->flags &= ~RGI_ON_LINK; } - } + } #endif } else @@ -3440,8 +3450,8 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, /* we're only looking for routes in the main table, as "we have * no IPv6" will lead to a lookup result in "Local" (::/0 reject) */ - if ((rtm->rtm_family != AF_INET6) || - (rtm->rtm_table != RT_TABLE_MAIN)) + if ((rtm->rtm_family != AF_INET6) + || (rtm->rtm_table != RT_TABLE_MAIN)) { /* we're not interested */ continue; @@ -3495,9 +3505,9 @@ done: } } -#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) || \ - defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || \ - defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) +#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) \ + || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ + || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) #include <sys/types.h> #include <sys/socket.h> @@ -3726,7 +3736,7 @@ get_default_gateway(struct route_gateway_info *rgi) close(sockfd); sockfd = -1; - for (cp = buffer; cp <= (buffer + ifc.ifc_len - sizeof(struct ifreq));) + for (cp = buffer; cp <= (buffer + ifc.ifc_len - sizeof(struct ifreq)); ) { ifr = (struct ifreq *)cp; #if defined(TARGET_SOLARIS) @@ -3811,8 +3821,8 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, so_dst.sin6_family = AF_INET6; so_mask.sin6_family = AF_INET6; - if ((dest != NULL) && /* specific host? */ - !IN6_IS_ADDR_UNSPECIFIED(dest)) + if ((dest != NULL) /* specific host? */ + && !IN6_IS_ADDR_UNSPECIFIED(dest)) { so_dst.sin6_addr = *dest; /* :: needs /0 "netmask", host route wants "no netmask */ @@ -4032,8 +4042,8 @@ netmask_to_netbits2(in_addr_t netmask) static void add_host_route_if_nonlocal(struct route_bypass *rb, const in_addr_t addr) { - if ((test_local_addr(addr, NULL) == TLA_NONLOCAL) && - (addr != 0) && (addr != IPV4_NETMASK_HOST)) + if ((test_local_addr(addr, NULL) == TLA_NONLOCAL) + && (addr != 0) && (addr != IPV4_NETMASK_HOST)) { add_bypass_address(rb, addr); }
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel