Lines 1-4
Link Here
|
1 |
--- pf/obsdrdr.c.orig 2023-02-17 03:09:33 UTC |
1 |
--- pf/obsdrdr.c.orig 2024-03-19 23:41:25 UTC |
2 |
+++ pf/obsdrdr.c |
2 |
+++ pf/obsdrdr.c |
3 |
@@ -64,6 +64,8 @@ |
3 |
@@ -64,6 +64,8 @@ |
4 |
#include <stdio.h> |
4 |
#include <stdio.h> |
Lines 9-15
Link Here
|
9 |
#include "../macros.h" |
9 |
#include "../macros.h" |
10 |
#include "config.h" |
10 |
#include "config.h" |
11 |
#include "obsdrdr.h" |
11 |
#include "obsdrdr.h" |
12 |
@@ -154,7 +156,7 @@ init_redirect(void) |
12 |
@@ -155,7 +157,7 @@ init_redirect(void) |
13 |
int |
13 |
int |
14 |
init_redirect(void) |
14 |
init_redirect(void) |
15 |
{ |
15 |
{ |
Lines 18-24
Link Here
|
18 |
if(dev>=0) |
18 |
if(dev>=0) |
19 |
shutdown_redirect(); |
19 |
shutdown_redirect(); |
20 |
dev = open("/dev/pf", O_RDWR); |
20 |
dev = open("/dev/pf", O_RDWR); |
21 |
@@ -162,14 +164,16 @@ init_redirect(void) |
21 |
@@ -163,14 +165,16 @@ init_redirect(void) |
22 |
syslog(LOG_ERR, "open(\"/dev/pf\"): %m"); |
22 |
syslog(LOG_ERR, "open(\"/dev/pf\"): %m"); |
23 |
return -1; |
23 |
return -1; |
24 |
} |
24 |
} |
Lines 37-59
Link Here
|
37 |
return 0; |
37 |
return 0; |
38 |
} |
38 |
} |
39 |
|
39 |
|
40 |
@@ -464,6 +468,7 @@ delete_nat_rule(const char * ifname, unsigned short ip |
40 |
@@ -471,6 +475,7 @@ delete_nat_rule(const char * ifname, unsigned short ip |
41 |
{ |
41 |
int i, n, r; |
42 |
int i, n; |
42 |
unsigned int tnum; |
43 |
struct pfioc_rule pr; |
43 |
struct pfioc_rule pr; |
44 |
+ struct pfctl_rule rule; |
44 |
+ struct pfctl_rule rule; |
45 |
UNUSED(ifname); |
45 |
UNUSED(ifname); |
46 |
if(dev<0) { |
46 |
if(dev<0) { |
47 |
syslog(LOG_ERR, "pf device is not open"); |
47 |
syslog(LOG_ERR, "pf device is not open"); |
48 |
@@ -486,19 +491,19 @@ delete_nat_rule(const char * ifname, unsigned short ip |
48 |
@@ -486,7 +491,7 @@ delete_nat_rule(const char * ifname, unsigned short ip |
|
|
49 |
#endif |
50 |
if(ioctl(dev, DIOCGETRULES, &pr) < 0) |
51 |
{ |
52 |
- syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); |
53 |
+ syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...) (%s:%d): %m", __func__, __LINE__); |
54 |
return -1; |
55 |
} |
56 |
n = pr.nr; |
57 |
@@ -497,7 +502,7 @@ delete_nat_rule(const char * ifname, unsigned short ip |
49 |
for(i=0; i<n; i++) |
58 |
for(i=0; i<n; i++) |
50 |
{ |
59 |
{ |
51 |
pr.nr = i; |
60 |
pr.nr = i; |
52 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
61 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
53 |
+ if (pfctl_get_rule(dev, i, pr.ticket, pr.anchor, pr.action, &rule, pr.anchor_call) < 0) |
62 |
+ if (pfctl_get_rule(dev, i, pr.ticket, pr.anchor, PF_NAT, &rule, pr.anchor_call) != 0) |
54 |
{ |
63 |
{ |
55 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
64 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
56 |
goto error; |
65 |
r = -1; |
|
|
66 |
@@ -505,12 +510,12 @@ delete_nat_rule(const char * ifname, unsigned short ip |
57 |
} |
67 |
} |
58 |
#ifdef TEST |
68 |
#ifdef TEST |
59 |
syslog(LOG_DEBUG, "%2d port=%hu proto=%d addr=%8x %8x", |
69 |
syslog(LOG_DEBUG, "%2d port=%hu proto=%d addr=%8x %8x", |
Lines 71-93
Link Here
|
71 |
{ |
81 |
{ |
72 |
pr.action = PF_CHANGE_GET_TICKET; |
82 |
pr.action = PF_CHANGE_GET_TICKET; |
73 |
if(ioctl(dev, DIOCCHANGERULE, &pr) < 0) |
83 |
if(ioctl(dev, DIOCCHANGERULE, &pr) < 0) |
74 |
@@ -843,6 +848,7 @@ get_redirect_rule(const char * ifname, unsigned short |
84 |
@@ -842,7 +847,7 @@ get_redirect_rule_count(const char * ifname) |
|
|
85 |
#endif |
86 |
if(ioctl(dev, DIOCGETRULES, &pr) < 0) |
87 |
{ |
88 |
- syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); |
89 |
+ syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...) (%s:%d): %m", __func__, __LINE__); |
90 |
return -1; |
91 |
} |
92 |
release_ticket(dev, pr.ticket); |
93 |
@@ -863,7 +868,9 @@ get_redirect_rule(const char * ifname, unsigned short |
75 |
{ |
94 |
{ |
76 |
int i, n; |
95 |
int i, n, r; |
77 |
struct pfioc_rule pr; |
96 |
unsigned int tnum; |
|
|
97 |
- struct pfioc_rule pr; |
98 |
+ struct pfctl_rules_info info; |
78 |
+ struct pfctl_rule rule; |
99 |
+ struct pfctl_rule rule; |
|
|
100 |
+ char anchor_call[MAXPATHLEN]; |
79 |
#ifndef PF_NEWSTYLE |
101 |
#ifndef PF_NEWSTYLE |
80 |
struct pfioc_pooladdr pp; |
102 |
struct pfioc_pooladdr pp; |
81 |
#endif |
103 |
#endif |
82 |
@@ -866,37 +872,37 @@ get_redirect_rule(const char * ifname, unsigned short |
104 |
@@ -873,63 +880,57 @@ get_redirect_rule(const char * ifname, unsigned short |
|
|
105 |
syslog(LOG_ERR, "pf device is not open"); |
106 |
return -1; |
107 |
} |
108 |
- memset(&pr, 0, sizeof(pr)); |
109 |
- strlcpy(pr.anchor, anchor_name, MAXPATHLEN); |
110 |
-#ifndef PF_NEWSTYLE |
111 |
- pr.rule.action = PF_RDR; |
112 |
-#endif |
113 |
- if(ioctl(dev, DIOCGETRULES, &pr) < 0) |
114 |
+ if (pfctl_get_rules_info(dev, &info, PF_RDR, anchor_name) != 0) |
115 |
{ |
116 |
- syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); |
117 |
+ syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...) (%s:%d): %m", __func__, __LINE__); |
118 |
return -1; |
119 |
} |
120 |
- n = pr.nr; |
121 |
+ n = info.nr; |
122 |
#ifdef PF_RELEASETICKETS |
123 |
- tnum = pr.ticket; |
124 |
+ tnum = info.ticket; |
125 |
#endif /* PF_RELEASETICKETS */ |
126 |
r = -2; |
83 |
for(i=0; i<n; i++) |
127 |
for(i=0; i<n; i++) |
84 |
{ |
128 |
{ |
85 |
pr.nr = i; |
129 |
- pr.nr = i; |
86 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
130 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
87 |
+ if (pfctl_get_rule(dev, i, pr.ticket, pr.anchor, pr.action, &rule, pr.anchor_call) < 0) |
131 |
+ if (pfctl_get_rule(dev, i, info.ticket, anchor_name, PF_RDR, &rule, anchor_call) != 0) |
88 |
{ |
132 |
{ |
89 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
133 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
90 |
goto error; |
134 |
r = -1; |
|
|
135 |
break; |
91 |
} |
136 |
} |
92 |
#ifdef __APPLE__ |
137 |
#ifdef __APPLE__ |
93 |
- if( (eport == ntohs(pr.rule.dst.xport.range.port[0])) |
138 |
- if( (eport == ntohs(pr.rule.dst.xport.range.port[0])) |
Lines 130-136
Link Here
|
130 |
#endif |
175 |
#endif |
131 |
#ifndef PF_NEWSTYLE |
176 |
#ifndef PF_NEWSTYLE |
132 |
memset(&pp, 0, sizeof(pp)); |
177 |
memset(&pp, 0, sizeof(pp)); |
133 |
@@ -928,15 +934,15 @@ get_redirect_rule(const char * ifname, unsigned short |
178 |
strlcpy(pp.anchor, anchor_name, MAXPATHLEN); |
|
|
179 |
pp.r_action = PF_RDR; |
180 |
pp.r_num = i; |
181 |
- pp.ticket = pr.ticket; |
182 |
+ pp.ticket = info.ticket; |
183 |
if(ioctl(dev, DIOCGETADDRS, &pp) < 0) |
184 |
{ |
185 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETADDRS, ...): %m"); |
186 |
@@ -957,15 +958,15 @@ get_redirect_rule(const char * ifname, unsigned short |
134 |
iaddr, iaddrlen); |
187 |
iaddr, iaddrlen); |
135 |
#endif |
188 |
#endif |
136 |
#else |
189 |
#else |
Lines 149-155
Link Here
|
149 |
#endif |
202 |
#endif |
150 |
{ |
203 |
{ |
151 |
rhost[0] = '\0'; /* empty string */ |
204 |
rhost[0] = '\0'; /* empty string */ |
152 |
@@ -944,10 +950,10 @@ get_redirect_rule(const char * ifname, unsigned short |
205 |
@@ -973,10 +974,10 @@ get_redirect_rule(const char * ifname, unsigned short |
153 |
else |
206 |
else |
154 |
{ |
207 |
{ |
155 |
#ifdef PFVAR_NEW_STYLE |
208 |
#ifdef PFVAR_NEW_STYLE |
Lines 162-184
Link Here
|
162 |
rhost, rhostlen); |
215 |
rhost, rhostlen); |
163 |
#endif |
216 |
#endif |
164 |
} |
217 |
} |
165 |
@@ -978,6 +984,7 @@ priv_delete_redirect_rule_check_desc(const char * ifna |
218 |
@@ -1010,6 +1011,7 @@ priv_delete_redirect_rule_check_desc(const char * ifna |
166 |
{ |
219 |
int i, n, r; |
167 |
int i, n; |
220 |
unsigned int tnum; |
168 |
struct pfioc_rule pr; |
221 |
struct pfioc_rule pr; |
169 |
+ struct pfctl_rule rule; |
222 |
+ struct pfctl_rule rule; |
170 |
UNUSED(ifname); |
223 |
UNUSED(ifname); |
171 |
|
224 |
|
172 |
if(dev<0) { |
225 |
if(dev<0) { |
173 |
@@ -998,23 +1005,23 @@ priv_delete_redirect_rule_check_desc(const char * ifna |
226 |
@@ -1023,7 +1025,7 @@ priv_delete_redirect_rule_check_desc(const char * ifna |
|
|
227 |
#endif |
228 |
if(ioctl(dev, DIOCGETRULES, &pr) < 0) |
229 |
{ |
230 |
- syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); |
231 |
+ syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...) (%s:%d): %m", __func__, __LINE__); |
232 |
return -1; |
233 |
} |
234 |
n = pr.nr; |
235 |
@@ -1034,24 +1036,24 @@ priv_delete_redirect_rule_check_desc(const char * ifna |
174 |
for(i=0; i<n; i++) |
236 |
for(i=0; i<n; i++) |
175 |
{ |
237 |
{ |
176 |
pr.nr = i; |
238 |
pr.nr = i; |
177 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
239 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
178 |
+ if (pfctl_get_rule(dev, i, pr.ticket, pr.anchor, pr.action, &rule, pr.anchor_call) < 0) |
240 |
+ if (pfctl_get_rule(dev, i, pr.ticket, pr.anchor, PF_RDR, &rule, pr.anchor_call) != 0) |
179 |
{ |
241 |
{ |
180 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
242 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
181 |
goto error; |
243 |
r = -1; |
|
|
244 |
break; |
182 |
} |
245 |
} |
183 |
#ifdef __APPLE__ |
246 |
#ifdef __APPLE__ |
184 |
- if( (eport == ntohs(pr.rule.dst.xport.range.port[0])) |
247 |
- if( (eport == ntohs(pr.rule.dst.xport.range.port[0])) |
Lines 201-207
Link Here
|
201 |
if(iaddr) |
264 |
if(iaddr) |
202 |
{ |
265 |
{ |
203 |
/* retrieve internal address */ |
266 |
/* retrieve internal address */ |
204 |
@@ -1047,33 +1054,33 @@ priv_delete_redirect_rule_check_desc(const char * ifna |
267 |
@@ -1087,33 +1089,33 @@ priv_delete_redirect_rule_check_desc(const char * ifna |
205 |
#endif |
268 |
#endif |
206 |
} |
269 |
} |
207 |
#else |
270 |
#else |
Lines 240-262
Link Here
|
240 |
- (desc && 0 == strcmp(desc, pr.rule.label))) { |
303 |
- (desc && 0 == strcmp(desc, pr.rule.label))) { |
241 |
+ if((desc == NULL && rule.label[0][0] == '\0') || |
304 |
+ if((desc == NULL && rule.label[0][0] == '\0') || |
242 |
+ (desc && 0 == strcmp(desc, rule.label[0]))) { |
305 |
+ (desc && 0 == strcmp(desc, rule.label[0]))) { |
243 |
return 1; |
306 |
r = 1; |
|
|
307 |
break; |
244 |
} |
308 |
} |
245 |
} |
309 |
@@ -1175,7 +1177,7 @@ priv_delete_filter_rule(const char * ifname, unsigned |
246 |
@@ -1208,6 +1215,7 @@ get_redirect_rule_by_index(int index, |
310 |
pr.rule.action = PF_PASS; |
247 |
{ |
311 |
if(ioctl(dev, DIOCGETRULES, &pr) < 0) |
248 |
int n; |
312 |
{ |
|
|
313 |
- syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); |
314 |
+ syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...) (%s:%d): %m", __func__, __LINE__); |
315 |
return -1; |
316 |
} |
317 |
n = pr.nr; |
318 |
@@ -1275,6 +1277,7 @@ get_redirect_rule_by_index(int index, |
319 |
int n, r; |
320 |
unsigned int tnum; |
249 |
struct pfioc_rule pr; |
321 |
struct pfioc_rule pr; |
250 |
+ struct pfctl_rule rule; |
322 |
+ struct pfctl_rule rule; |
251 |
#ifndef PF_NEWSTYLE |
323 |
#ifndef PF_NEWSTYLE |
252 |
struct pfioc_pooladdr pp; |
324 |
struct pfioc_pooladdr pp; |
253 |
#endif |
325 |
#endif |
254 |
@@ -1231,36 +1239,36 @@ get_redirect_rule_by_index(int index, |
326 |
@@ -1291,7 +1294,7 @@ get_redirect_rule_by_index(int index, |
|
|
327 |
#endif |
328 |
if(ioctl(dev, DIOCGETRULES, &pr) < 0) |
329 |
{ |
330 |
- syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); |
331 |
+ syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...) (%s:%d): %m", __func__, __LINE__); |
332 |
return -1; |
333 |
} |
334 |
n = pr.nr; |
335 |
@@ -1302,36 +1305,36 @@ get_redirect_rule_by_index(int index, |
255 |
if(index >= n) |
336 |
if(index >= n) |
256 |
goto error; |
337 |
goto error; |
257 |
pr.nr = index; |
338 |
pr.nr = index; |
258 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
339 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
259 |
+ if (pfctl_get_rule(dev, index, pr.ticket, pr.anchor, pr.action, &rule, pr.anchor_call) < 0) |
340 |
+ if (pfctl_get_rule(dev, index, pr.ticket, pr.anchor, PF_RDR, &rule, pr.anchor_call) != 0) |
260 |
{ |
341 |
{ |
261 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
342 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
262 |
goto error; |
343 |
goto error; |
Lines 300-306
Link Here
|
300 |
#endif |
381 |
#endif |
301 |
#ifndef PF_NEWSTYLE |
382 |
#ifndef PF_NEWSTYLE |
302 |
memset(&pp, 0, sizeof(pp)); |
383 |
memset(&pp, 0, sizeof(pp)); |
303 |
@@ -1292,15 +1300,15 @@ get_redirect_rule_by_index(int index, |
384 |
@@ -1363,15 +1366,15 @@ get_redirect_rule_by_index(int index, |
304 |
iaddr, iaddrlen); |
385 |
iaddr, iaddrlen); |
305 |
#endif |
386 |
#endif |
306 |
#else |
387 |
#else |
Lines 319-325
Link Here
|
319 |
#endif |
400 |
#endif |
320 |
{ |
401 |
{ |
321 |
rhost[0] = '\0'; /* empty string */ |
402 |
rhost[0] = '\0'; /* empty string */ |
322 |
@@ -1308,10 +1316,10 @@ get_redirect_rule_by_index(int index, |
403 |
@@ -1379,10 +1382,10 @@ get_redirect_rule_by_index(int index, |
323 |
else |
404 |
else |
324 |
{ |
405 |
{ |
325 |
#ifdef PFVAR_NEW_STYLE |
406 |
#ifdef PFVAR_NEW_STYLE |
Lines 332-338
Link Here
|
332 |
rhost, rhostlen); |
413 |
rhost, rhostlen); |
333 |
#endif |
414 |
#endif |
334 |
} |
415 |
} |
335 |
@@ -1334,6 +1342,7 @@ get_portmappings_in_range(unsigned short startport, un |
416 |
@@ -1406,6 +1409,7 @@ get_portmappings_in_range(unsigned short startport, un |
336 |
int i, n; |
417 |
int i, n; |
337 |
unsigned short eport; |
418 |
unsigned short eport; |
338 |
struct pfioc_rule pr; |
419 |
struct pfioc_rule pr; |
Lines 340-351
Link Here
|
340 |
|
421 |
|
341 |
*number = 0; |
422 |
*number = 0; |
342 |
if(dev<0) { |
423 |
if(dev<0) { |
343 |
@@ -1362,19 +1371,19 @@ get_portmappings_in_range(unsigned short startport, un |
424 |
@@ -1426,7 +1430,7 @@ get_portmappings_in_range(unsigned short startport, un |
|
|
425 |
#endif |
426 |
if(ioctl(dev, DIOCGETRULES, &pr) < 0) |
427 |
{ |
428 |
- syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); |
429 |
+ syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...) (%s:%d): %m", __func__, __LINE__); |
430 |
free(array); |
431 |
return NULL; |
432 |
} |
433 |
@@ -1437,19 +1441,19 @@ get_portmappings_in_range(unsigned short startport, un |
344 |
for(i=0; i<n; i++) |
434 |
for(i=0; i<n; i++) |
345 |
{ |
435 |
{ |
346 |
pr.nr = i; |
436 |
pr.nr = i; |
347 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
437 |
- if(ioctl(dev, DIOCGETRULE, &pr) < 0) |
348 |
+ if (pfctl_get_rule(dev, i, pr.ticket, pr.anchor, pr.action, &rule, pr.anchor_call) < 0) |
438 |
+ if (pfctl_get_rule(dev, i, pr.ticket, pr.anchor, PF_RDR, &rule, pr.anchor_call) != 0) |
349 |
{ |
439 |
{ |
350 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
440 |
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); |
351 |
continue; |
441 |
continue; |