-/* $OpenBSD: iked.h,v 1.191 2021/05/13 15:20:48 tobhe Exp $ */
+/* $OpenBSD: iked.h,v 1.192 2021/06/23 12:11:40 tobhe Exp $ */
/*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
/* vroute.c */
void vroute_init(struct iked *);
+int vroute_setaddr(struct iked *, int, struct sockaddr *, int, unsigned int);
void vroute_cleanup(struct iked *);
int vroute_getaddr(struct iked *, struct imsg *);
int vroute_setaddroute(struct iked *, uint8_t, struct sockaddr *,
-/* $OpenBSD: policy.c,v 1.81 2021/04/09 09:15:04 tobhe Exp $ */
+/* $OpenBSD: policy.c,v 1.82 2021/06/23 12:11:40 tobhe Exp $ */
/*
* Copyright (c) 2020-2021 Tobias Heider <tobhe@openbsd.org>
sa_configure_iface(struct iked *env, struct iked_sa *sa, int add)
{
struct iked_flow *saflow;
- struct iovec iov[4];
- int iovcnt;
struct sockaddr *caddr;
- struct sockaddr_in *addr;
- struct sockaddr_in mask;
- struct sockaddr_in6 *addr6;
- struct sockaddr_in6 mask6;
int rdomain;
if (sa->sa_policy == NULL || sa->sa_policy->pol_iface == 0)
return (0);
if (sa->sa_cp_addr) {
- iovcnt = 0;
- addr = (struct sockaddr_in *)&sa->sa_cp_addr->addr;
- iov[0].iov_base = addr;
- iov[0].iov_len = sizeof(*addr);
- iovcnt++;
-
- bzero(&mask, sizeof(mask));
- mask.sin_addr.s_addr =
- prefixlen2mask(sa->sa_cp_addr->addr_mask ?
- sa->sa_cp_addr->addr_mask : 32);
- mask.sin_family = AF_INET;
- mask.sin_len = sizeof(mask);
- iov[1].iov_base = &mask;
- iov[1].iov_len = sizeof(mask);
- iovcnt++;
-
- iov[2].iov_base = &sa->sa_policy->pol_iface;
- iov[2].iov_len = sizeof(sa->sa_policy->pol_iface);
- iovcnt++;
-
- if(proc_composev(&env->sc_ps, PROC_PARENT,
- add ? IMSG_IF_ADDADDR : IMSG_IF_DELADDR,
- iov, iovcnt))
+ if (vroute_setaddr(env, add,
+ (struct sockaddr *)&sa->sa_cp_addr->addr,
+ sa->sa_cp_addr->addr_mask, sa->sa_policy->pol_iface) != 0)
return (-1);
}
if (sa->sa_cp_addr6) {
- iovcnt = 0;
- addr6 = (struct sockaddr_in6 *)&sa->sa_cp_addr6->addr;
- iov[0].iov_base = addr6;
- iov[0].iov_len = sizeof(*addr6);
- iovcnt++;
-
- bzero(&mask6, sizeof(mask6));
- prefixlen2mask6(sa->sa_cp_addr6->addr_mask ?
- sa->sa_cp_addr6->addr_mask : 128,
- (uint32_t *)&mask6.sin6_addr.s6_addr);
- mask6.sin6_family = AF_INET6;
- mask6.sin6_len = sizeof(mask6);
- iov[1].iov_base = &mask6;
- iov[1].iov_len = sizeof(mask6);
- iovcnt++;
-
- iov[2].iov_base = &sa->sa_policy->pol_iface;
- iov[2].iov_len = sizeof(sa->sa_policy->pol_iface);
- iovcnt++;
-
- if(proc_composev(&env->sc_ps, PROC_PARENT,
- add ? IMSG_IF_ADDADDR : IMSG_IF_DELADDR,
- iov, iovcnt))
+ if (vroute_setaddr(env, add,
+ (struct sockaddr *)&sa->sa_cp_addr6->addr,
+ sa->sa_cp_addr6->addr_mask, sa->sa_policy->pol_iface) != 0)
return (-1);
}
-/* $OpenBSD: vroute.c,v 1.10 2021/06/01 20:57:12 tobhe Exp $ */
+/* $OpenBSD: vroute.c,v 1.11 2021/06/23 12:11:40 tobhe Exp $ */
/*
* Copyright (c) 2021 Tobias Heider <tobhe@openbsd.org>
}
}
+int
+vroute_setaddr(struct iked *env, int add, struct sockaddr *addr,
+ int mask, unsigned int ifidx)
+{
+ struct iovec iov[4];
+ int iovcnt;
+ struct sockaddr_in mask4;
+ struct sockaddr_in6 mask6;
+
+ iovcnt = 0;
+ iov[0].iov_base = addr;
+ iov[0].iov_len = addr->sa_len;
+ iovcnt++;
+
+ switch(addr->sa_family) {
+ case AF_INET:
+ bzero(&mask, sizeof(mask));
+ mask4.sin_addr.s_addr = prefixlen2mask(mask ? mask : 32);
+ mask4.sin_family = AF_INET;
+ mask4.sin_len = sizeof(mask4);
+
+ iov[1].iov_base = &mask4;
+ iov[1].iov_len = sizeof(mask4);
+ iovcnt++;
+ break;
+ case AF_INET6:
+ bzero(&mask6, sizeof(mask6));
+ prefixlen2mask6(mask ? mask : 128,
+ (uint32_t *)&mask6.sin6_addr.s6_addr);
+ mask6.sin6_family = AF_INET6;
+ mask6.sin6_len = sizeof(mask6);
+ iov[1].iov_base = &mask6;
+ iov[1].iov_len = sizeof(mask6);
+ iovcnt++;
+ break;
+ default:
+ return -1;
+ }
+
+ iov[2].iov_base = &ifidx;
+ iov[2].iov_len = sizeof(ifidx);
+ iovcnt++;
+
+ return (proc_composev(&env->sc_ps, PROC_PARENT,
+ add ? IMSG_IF_ADDADDR : IMSG_IF_DELADDR, iov, iovcnt));
+}
+
int
vroute_getaddr(struct iked *env, struct imsg *imsg)
{