-/* $OpenBSD: pfctl_parser.c,v 1.328 2018/09/05 08:47:21 kn Exp $ */
+/* $OpenBSD: pfctl_parser.c,v 1.329 2018/09/05 21:16:26 kn Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
}
void
-set_ipmask(struct node_host *h, u_int8_t b)
+set_ipmask(struct node_host *h, int bb)
{
struct pf_addr *m, *n;
int i, j = 0;
+ u_int8_t b;
m = &h->addr.v.a.mask;
memset(m, 0, sizeof(*m));
+ if (bb == -1)
+ b = h->af == AF_INET ? 32 : 128;
+ else
+ b = bb;
+
while (b >= 32) {
m->addr32[j++] = 0xffffffff;
b -= 32;
if (flags & PFI_AFLAG_NETWORK)
set_ipmask(n, unmask(&p->addr.v.a.mask, n->af));
else {
- if (n->af == AF_INET) {
- if (p->ifa_flags & IFF_LOOPBACK &&
- p->ifa_flags & IFF_LINK1)
- memcpy(&n->addr.v.a.mask,
- &p->addr.v.a.mask,
- sizeof(struct pf_addr));
- else
- set_ipmask(n, 32);
- } else
- set_ipmask(n, 128);
+ if (n->af == AF_INET &&
+ p->ifa_flags & IFF_LOOPBACK &&
+ p->ifa_flags & IFF_LINK1)
+ memcpy(&n->addr.v.a.mask, &p->addr.v.a.mask,
+ sizeof(struct pf_addr));
+ else
+ set_ipmask(n, -1);
}
n->ifindex = p->ifindex;
if (ifa_exists(ps) || !strncmp(ps, "self", IFNAMSIZ)) {
/* interface with this name exists */
h = ifa_lookup(ps, flags);
- for (n = h; n != NULL && mask > -1; n = n->next)
- set_ipmask(n, mask);
+ if (mask > -1)
+ for (n = h; n != NULL; n = n->next)
+ set_ipmask(n, mask);
}
error:
h->ifname = NULL;
h->af = AF_INET;
h->addr.v.a.addr.addr32[0] = ina.s_addr;
- set_ipmask(h, mask > -1 ? mask : 32);
+ set_ipmask(h, mask);
h->next = NULL;
h->tail = h;
sizeof(h->addr.v.a.addr));
h->ifindex =
((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
- set_ipmask(h, mask > -1 ? mask : 128);
+ set_ipmask(h, mask);
freeaddrinfo(res);
h->next = NULL;
h->tail = h;
&((struct sockaddr_in *)
res->ai_addr)->sin_addr.s_addr,
sizeof(struct in_addr));
- set_ipmask(n, mask > -1 ? mask : 32);
} else {
memcpy(&n->addr.v.a.addr,
&((struct sockaddr_in6 *)
n->ifindex =
((struct sockaddr_in6 *)
res->ai_addr)->sin6_scope_id;
- set_ipmask(n, mask > -1 ? mask : 128);
}
+ set_ipmask(n, mask);
n->next = NULL;
n->tail = n;
if (h == NULL)
-/* $OpenBSD: pfctl_parser.h,v 1.110 2018/02/08 09:15:46 henning Exp $ */
+/* $OpenBSD: pfctl_parser.h,v 1.111 2018/09/05 21:16:26 kn Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
extern const struct pf_timeout pf_timeouts[];
-void set_ipmask(struct node_host *, u_int8_t);
+void set_ipmask(struct node_host *, int);
int check_netmask(struct node_host *, sa_family_t);
int unmask(struct pf_addr *, sa_family_t);
struct node_host *gen_dynnode(struct node_host *, sa_family_t);