* @param iface the interface where the address has to be added
* @param addr the address to add
* @param prefixlen the prefix length of the network associated with the address
- * @param broadcast the broadcast address to configure on the interface
*
* @return 0 on success, a negative error code otherwise
*/
int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
- const in_addr_t *addr, int prefixlen,
- const in_addr_t *broadcast);
+ const in_addr_t *addr, int prefixlen);
/**
* Add an IPv6 address to an interface
int
net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface,
- const in_addr_t *addr, int prefixlen,
- const in_addr_t *broadcast)
+ const in_addr_t *addr, int prefixlen)
{
struct argv argv = argv_new();
const char *addr_str = print_in_addr_t(*addr, 0, &ctx->gc);
- const char *brd_str = print_in_addr_t(*broadcast, 0, &ctx->gc);
- argv_printf(&argv, "%s addr add dev %s %s/%d broadcast %s", iproute_path,
- iface, addr_str, prefixlen, brd_str);
+ argv_printf(&argv, "%s addr add dev %s %s/%d", iproute_path, iface,
+ addr_str, prefixlen);
argv_msg(M_INFO, &argv);
openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip addr add failed");
static int
sitnl_addr_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family,
const inet_address_t *local, const inet_address_t *remote,
- int prefixlen, const inet_address_t *broadcast)
+ int prefixlen)
{
struct sitnl_addr_req req;
uint32_t size;
SITNL_ADDATTR(&req.n, sizeof(req), IFA_LOCAL, local, size);
}
- if (broadcast)
- {
- SITNL_ADDATTR(&req.n, sizeof(req), IFA_BROADCAST, broadcast, size);
- }
-
ret = sitnl_send(&req.n, 0, 0, NULL, NULL);
if ((ret < 0) && (errno == EEXIST))
{
}
return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifindex,
- af_family, local, remote, 0, NULL);
+ af_family, local, remote, 0);
}
static int
return -ENOENT;
}
- return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, local, NULL, 0,
- NULL);
+ return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, local, NULL, 0);
}
static int
static int
sitnl_addr_add(sa_family_t af_family, const char *iface,
- const inet_address_t *addr, int prefixlen,
- const inet_address_t *broadcast)
+ const inet_address_t *addr, int prefixlen)
{
int ifindex;
}
return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifindex,
- af_family, addr, NULL, prefixlen, broadcast);
+ af_family, addr, NULL, prefixlen);
}
static int
}
return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, addr, NULL,
- prefixlen, NULL);
+ prefixlen);
}
int
net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface,
- const in_addr_t *addr, int prefixlen,
- const in_addr_t *broadcast)
+ const in_addr_t *addr, int prefixlen)
{
inet_address_t addr_v4 = { 0 };
- inet_address_t brd_v4 = { 0 };
- char buf1[INET_ADDRSTRLEN];
- char buf2[INET_ADDRSTRLEN];
+ char buf[INET_ADDRSTRLEN];
if (!addr)
{
addr_v4.ipv4 = htonl(*addr);
- if (broadcast)
- {
- brd_v4.ipv4 = htonl(*broadcast);
- }
-
- msg(M_INFO, "%s: %s/%d brd %s dev %s", __func__,
- inet_ntop(AF_INET, &addr_v4.ipv4, buf1, sizeof(buf1)), prefixlen,
- inet_ntop(AF_INET, &brd_v4.ipv4, buf2, sizeof(buf2)), iface);
+ msg(M_INFO, "%s: %s/%d dev %s", __func__,
+ inet_ntop(AF_INET, &addr_v4.ipv4, buf, sizeof(buf)), prefixlen,iface);
- return sitnl_addr_add(AF_INET, iface, &addr_v4, prefixlen, &brd_v4);
+ return sitnl_addr_add(AF_INET, iface, &addr_v4, prefixlen);
}
int
msg(M_INFO, "%s: %s/%d dev %s", __func__,
inet_ntop(AF_INET6, &addr_v6.ipv6, buf, sizeof(buf)), prefixlen, iface);
- return sitnl_addr_add(AF_INET6, iface, &addr_v6, prefixlen, NULL);
+ return sitnl_addr_add(AF_INET6, iface, &addr_v6, prefixlen);
}
int
gc_free(&gc);
}
-/*
- * For TAP-style devices, generate a broadcast address.
- */
-static in_addr_t
-generate_ifconfig_broadcast_addr(in_addr_t local,
- in_addr_t netmask)
-{
- return local | ~netmask;
-}
-
/*
* Check that --local and --remote addresses do not
* clash with ifconfig addresses or subnet.
}
else
{
- const char *ifconfig_broadcast = print_in_addr_t(tt->broadcast, 0, &gc);
setenv_str(es, "ifconfig_netmask", ifconfig_remote_netmask);
- setenv_str(es, "ifconfig_broadcast", ifconfig_broadcast);
}
}
}
}
- /*
- * If TAP-style interface, generate broadcast address.
- */
- if (!tun)
- {
- tt->broadcast = generate_ifconfig_broadcast_addr(tt->local, tt->remote_netmask);
- }
-
#ifdef _WIN32
/*
* Make sure that both ifconfig addresses are part of the
#if !defined(TARGET_LINUX)
const char *ifconfig_local = NULL;
const char *ifconfig_remote_netmask = NULL;
- const char *ifconfig_broadcast = NULL;
struct argv argv = argv_new();
struct gc_arena gc = gc_new();
*/
ifconfig_local = print_in_addr_t(tt->local, 0, &gc);
ifconfig_remote_netmask = print_in_addr_t(tt->remote_netmask, 0, &gc);
-
- /*
- * If TAP-style device, generate broadcast address.
- */
- if (!tun)
- {
- ifconfig_broadcast = print_in_addr_t(tt->broadcast, 0, &gc);
- }
#endif
#if defined(TARGET_LINUX)
else
{
if (net_addr_v4_add(ctx, ifname, &tt->local,
- netmask_to_netbits2(tt->remote_netmask),
- &tt->remote_netmask) < 0)
+ netmask_to_netbits2(tt->remote_netmask)) < 0)
{
msg(M_FATAL, "Linux can't add IP to TAP interface %s", ifname);
}
}
else
{
- argv_printf(&argv, "%s %s %s netmask %s broadcast + up",
+ argv_printf(&argv, "%s %s %s netmask %s up",
IFCONFIG_PATH, ifname, ifconfig_local,
ifconfig_remote_netmask);
}
}
else
{
- argv_printf(&argv, "%s %s %s netmask %s mtu %d broadcast %s link0",
+ argv_printf(&argv, "%s %s %s netmask %s mtu %d link0",
IFCONFIG_PATH, ifname, ifconfig_local,
- ifconfig_remote_netmask, tun_mtu, ifconfig_broadcast);
+ ifconfig_remote_netmask, tun_mtu);
}
argv_msg(M_INFO, &argv);
openvpn_execve_check(&argv, es, S_FATAL, "OpenBSD ifconfig failed");
* so we don't need the "link0" extra parameter to specify we want to do
* tunneling at the ethernet level
*/
- argv_printf(&argv, "%s %s %s netmask %s mtu %d broadcast %s",
+ argv_printf(&argv, "%s %s %s netmask %s mtu %d",
IFCONFIG_PATH, ifname, ifconfig_local,
- ifconfig_remote_netmask, tun_mtu, ifconfig_broadcast);
+ ifconfig_remote_netmask, tun_mtu);
}
argv_msg(M_INFO, &argv);
openvpn_execve_check(&argv, es, S_FATAL, "NetBSD ifconfig failed");
/* ifconfig parameters */
in_addr_t local;
in_addr_t remote_netmask;
- in_addr_t broadcast;
struct in6_addr local_ipv6;
struct in6_addr remote_ipv6;
}
static int
-net__addr_v4_add(const char *addr_str, int prefixlen, const char *brd_str)
+net__addr_v4_add(const char *addr_str, int prefixlen)
{
- in_addr_t addr, brd;
+ in_addr_t addr;
int ret;
ret = inet_pton(AF_INET, addr_str, &addr);
if (ret != 1)
return -1;
- ret = inet_pton(AF_INET, brd_str, &brd);
- if (ret != 1)
- return -1;
-
addr = ntohl(addr);
- brd = ntohl(brd);
- printf("CMD: ip addr add %s/%d brd %s dev %s\n", addr_str, prefixlen,
- brd_str, iface);
+ printf("CMD: ip addr add %s/%d dev %s\n", addr_str, prefixlen, iface);
- return net_addr_v4_add(NULL, iface, &addr, prefixlen, &brd);
+ return net_addr_v4_add(NULL, iface, &addr, prefixlen);
}
static int
case 1:
return net__iface_mtu_set(1281);
case 2:
- return net__addr_v4_add("10.255.255.1", 24, "10.255.255.255");
+ return net__addr_v4_add("10.255.255.1", 24);
case 3:
return net__addr_v6_add("2001::1", 64);
case 4: