From b16787cd5ff04bebbd46348c0cddc3478316a28a Mon Sep 17 00:00:00 2001 From: Michael Nickerson Date: Thu, 7 Dec 2023 19:12:11 -0500 Subject: [PATCH] Fix for OpenBSD 7.4 Fixes a change made in OpenBSD 7.4 --- miniupnpd/pf/obsdrdr.c | 66 ++++++++++++++++++++++++++++++++++++++-- miniupnpd/pf/pfpinhole.c | 53 +++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 7 deletions(-) diff --git a/miniupnpd/pf/obsdrdr.c b/miniupnpd/pf/obsdrdr.c index 86c67f2..e9e05aa 100644 --- a/miniupnpd/pf/obsdrdr.c +++ b/miniupnpd/pf/obsdrdr.c @@ -1,8 +1,8 @@ -/* $Id: obsdrdr.c,v 1.101 2022/02/19 19:15:24 nanard Exp $ */ +/* $Id: obsdrdr.c,v 1.102 2023/12/07 18:56:32 nanard Exp $ */ /* vim: tabstop=4 shiftwidth=4 noexpandtab * MiniUPnP project * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ - * (c) 2006-2022 Thomas Bernard + * (c) 2006-2023 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -74,6 +74,17 @@ #error "USE_PF macro is undefined, check consistency between config.h and Makefile" #else +#if defined(PF_NEWSTYLE) && defined(DIOCXEND) +#define PF_RELEASETICKETS +#define release_ticket(device, ticket_num) {\ + if (ioctl((device), DIOCXEND, &(ticket_num)) < 0) {\ + syslog(LOG_ERR, "ioctl(dev, DIOCXEND, ...): %m");\ + }\ +} +#else +#define release_ticket(device, ticket_num) (void)(ticket_num) +#endif + /* list to keep timestamps for port mappings having a lease duration */ struct timestamp_entry { struct timestamp_entry * next; @@ -463,6 +474,7 @@ static int delete_nat_rule(const char * ifname, unsigned short iport, int proto, in_addr_t iaddr) { int i, n; + unsigned int tnum; struct pfioc_rule pr; UNUSED(ifname); if(dev<0) { @@ -483,12 +495,16 @@ delete_nat_rule(const char * ifname, unsigned short iport, int proto, in_addr_t goto error; } n = pr.nr; +#ifdef PF_RELEASETICKETS + tnum = pr.ticket; +#endif /* PF_RELEASETICKETS */ for(i=0; i= n) goto error; +#ifdef PF_RELEASETICKETS + tnum = pr.ticket; +#endif /* PF_RELEASETICKETS */ pr.nr = index; if(ioctl(dev, DIOCGETRULE, &pr) < 0) { syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); + release_ticket(dev, tnum); goto error; } *proto = pr.rule.proto; @@ -1318,6 +1370,7 @@ get_redirect_rule_by_index(int index, } if(timestamp) *timestamp = get_timestamp(*eport, *proto); + release_ticket(dev, tnum); return 0; error: return -1; @@ -1330,7 +1383,7 @@ get_portmappings_in_range(unsigned short startport, unsigned short endport, int proto, unsigned int * number) { unsigned short * array; - unsigned int capacity; + unsigned int capacity, tnum; int i, n; unsigned short eport; struct pfioc_rule pr; @@ -1359,6 +1412,9 @@ get_portmappings_in_range(unsigned short startport, unsigned short endport, return NULL; } n = pr.nr; +#ifdef PF_RELEASETICKETS + tnum = pr.ticket; +#endif /* PF_RELEASETICKETS */ for(i=0; i= 0; i--) { pr.nr = i; if(ioctl(dev, DIOCGETRULE, &pr) < 0) { syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); + release_ticket(dev, tnum); return -1; } if(sscanf(pr.rule.label, PINEHOLE_LABEL_FORMAT_SKIPDESC, &uid, &ts) != 2) { @@ -405,22 +443,28 @@ int clean_pinhole_list(unsigned int * next_timestamp) pr.action = PF_CHANGE_GET_TICKET; if(ioctl(dev, DIOCCHANGERULE, &pr) < 0) { syslog(LOG_ERR, "ioctl(dev, DIOCCHANGERULE, ...) PF_CHANGE_GET_TICKET: %m"); + release_ticket(dev, tnum); return -1; } pr.action = PF_CHANGE_REMOVE; pr.nr = i; if(ioctl(dev, DIOCCHANGERULE, &pr) < 0) { syslog(LOG_ERR, "ioctl(dev, DIOCCHANGERULE, ...) PF_CHANGE_REMOVE: %m"); + release_ticket(dev, tnum); return -1; } n++; #ifndef PF_NEWSTYLE pr.rule.action = PF_PASS; #endif + release_ticket(dev, tnum); if(ioctl(dev, DIOCGETRULES, &pr) < 0) { syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); return -1; } +#ifdef PF_RELEASETICKETS + tnum = pr.ticket; +#endif } else { if(uid > max_uid) max_uid = uid; @@ -440,6 +484,7 @@ int clean_pinhole_list(unsigned int * next_timestamp) next_uid = 1; } } + release_ticket(dev, tnum); return n; /* number of rules removed */ }