-/* $OpenBSD: pfctl_parser.c,v 1.332 2018/09/07 21:37:03 kn Exp $ */
+/* $OpenBSD: pfctl_parser.c,v 1.333 2018/09/10 16:17:48 kn Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
#include "pfctl_parser.h"
#include "pfctl.h"
+void copy_satopfaddr(struct pf_addr *, struct sockaddr *);
void print_op (u_int8_t, const char *, const char *);
void print_port (u_int8_t, u_int16_t, u_int16_t, const char *, int);
void print_ugid (u_int8_t, unsigned, unsigned, const char *, unsigned);
enum { PF_POOL_ROUTE, PF_POOL_NAT, PF_POOL_RDR };
+void
+copy_satopfaddr(struct pf_addr *pfa, struct sockaddr *sa)
+{
+ if (sa->sa_family == AF_INET6)
+ pfa->v6 = ((struct sockaddr_in6 *)sa)->sin6_addr;
+ else
+ pfa->v4 = ((struct sockaddr_in *)sa)->sin_addr;
+}
+
const struct icmptypeent *
geticmptypebynumber(u_int8_t type, sa_family_t af)
{
}
#endif
n->ifindex = 0;
- if (n->af == AF_INET) {
- memcpy(&n->addr.v.a.addr, &((struct sockaddr_in *)
- ifa->ifa_addr)->sin_addr.s_addr,
- sizeof(struct in_addr));
- memcpy(&n->addr.v.a.mask, &((struct sockaddr_in *)
- ifa->ifa_netmask)->sin_addr.s_addr,
- sizeof(struct in_addr));
- if (ifa->ifa_broadaddr != NULL)
- memcpy(&n->bcast, &((struct sockaddr_in *)
- ifa->ifa_broadaddr)->sin_addr.s_addr,
- sizeof(struct in_addr));
- if (ifa->ifa_dstaddr != NULL)
- memcpy(&n->peer, &((struct sockaddr_in *)
- ifa->ifa_dstaddr)->sin_addr.s_addr,
- sizeof(struct in_addr));
- } else if (n->af == AF_INET6) {
- memcpy(&n->addr.v.a.addr, &((struct sockaddr_in6 *)
- ifa->ifa_addr)->sin6_addr.s6_addr,
- sizeof(struct in6_addr));
- memcpy(&n->addr.v.a.mask, &((struct sockaddr_in6 *)
- ifa->ifa_netmask)->sin6_addr.s6_addr,
- sizeof(struct in6_addr));
- if (ifa->ifa_broadaddr != NULL)
- memcpy(&n->bcast, &((struct sockaddr_in6 *)
- ifa->ifa_broadaddr)->sin6_addr.s6_addr,
- sizeof(struct in6_addr));
- if (ifa->ifa_dstaddr != NULL)
- memcpy(&n->peer, &((struct sockaddr_in6 *)
- ifa->ifa_dstaddr)->sin6_addr.s6_addr,
- sizeof(struct in6_addr));
- n->ifindex = ((struct sockaddr_in6 *)
- ifa->ifa_addr)->sin6_scope_id;
- } else if (n->af == AF_LINK) {
+ if (n->af == AF_LINK)
n->ifindex = ((struct sockaddr_dl *)
ifa->ifa_addr)->sdl_index;
+ else {
+ copy_satopfaddr(&n->addr.v.a.addr, ifa->ifa_addr);
+ copy_satopfaddr(&n->addr.v.a.mask, ifa->ifa_netmask);
+ if (ifa->ifa_broadaddr != NULL)
+ copy_satopfaddr(&n->bcast, ifa->ifa_broadaddr);
+ if (ifa->ifa_dstaddr != NULL)
+ copy_satopfaddr(&n->peer, ifa->ifa_dstaddr);
+ if (n->af == AF_INET6)
+ n->ifindex = ((struct sockaddr_in6 *)
+ ifa->ifa_addr)->sin6_scope_id;
}
if ((n->ifname = strdup(ifa->ifa_name)) == NULL)
err(1, "%s: strdup", __func__);
err(1, "address: calloc");
h->ifname = NULL;
h->af = AF_INET6;
- memcpy(&h->addr.v.a.addr,
- &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
- sizeof(h->addr.v.a.addr));
+ copy_satopfaddr(&h->addr.v.a.addr, res->ai_addr);
h->ifindex =
((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
set_ipmask(h, mask);
err(1, "host_dns: calloc");
n->ifname = NULL;
n->af = res->ai_family;
- if (res->ai_family == AF_INET) {
- memcpy(&n->addr.v.a.addr,
- &((struct sockaddr_in *)
- res->ai_addr)->sin_addr.s_addr,
- sizeof(struct in_addr));
- } else {
- memcpy(&n->addr.v.a.addr,
- &((struct sockaddr_in6 *)
- res->ai_addr)->sin6_addr.s6_addr,
- sizeof(struct in6_addr));
+ copy_satopfaddr(&n->addr.v.a.addr, res->ai_addr);
+ if (res->ai_family == AF_INET6)
n->ifindex =
- ((struct sockaddr_in6 *)
- res->ai_addr)->sin6_scope_id;
- }
+ ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
set_ipmask(n, mask);
n->next = NULL;
n->tail = n;