1
|
diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
|
2
|
index 4925416..ce0867c 100644
|
3
|
--- a/sbin/pfctl/parse.y
|
4
|
+++ b/sbin/pfctl/parse.y
|
5
|
@@ -234,6 +234,7 @@ struct filter_opts {
|
6
|
u_int32_t tos;
|
7
|
u_int32_t dscp;
|
8
|
u_int32_t prob;
|
9
|
+ u_int32_t tracker;
|
10
|
struct {
|
11
|
int action;
|
12
|
struct node_state_opt *options;
|
13
|
@@ -263,6 +264,7 @@ struct filter_opts {
|
14
|
|
15
|
struct antispoof_opts {
|
16
|
char *label;
|
17
|
+ u_int32_t tracker;
|
18
|
u_int rtableid;
|
19
|
} antispoof_opts;
|
20
|
|
21
|
@@ -462,7 +464,7 @@ int parseport(char *, struct range *r, int);
|
22
|
%token RETURNRST RETURNICMP RETURNICMP6 PROTO INET INET6 ALL ANY ICMPTYPE
|
23
|
%token ICMP6TYPE CODE KEEP MODULATE STATE PORT RDR NAT BINAT ARROW NODF
|
24
|
%token MINTTL ERROR ALLOWOPTS FASTROUTE FILENAME ROUTETO DUPTO REPLYTO NO LABEL SCHEDULE
|
25
|
-%token NOROUTE URPFFAILED FRAGMENT USER GROUP MAXMSS MAXIMUM TTL TOS DSCP DROP TABLE
|
26
|
+%token NOROUTE URPFFAILED FRAGMENT USER GROUP MAXMSS MAXIMUM TTL TOS DSCP DROP TABLE TRACKER
|
27
|
%token REASSEMBLE FRAGDROP FRAGCROP ANCHOR NATANCHOR RDRANCHOR BINATANCHOR
|
28
|
%token SET OPTIMIZATION TIMEOUT LIMIT LOGINTERFACE BLOCKPOLICY RANDOMID
|
29
|
%token REQUIREORDER SYNPROXY FINGERPRINTS NOSYNC DEBUG SKIP HOSTID
|
30
|
@@ -1245,6 +1247,7 @@ antispoof : ANTISPOOF logquick antispoof_ifspc af antispoof_opts {
|
31
|
if (rule_label(&r, $5.label))
|
32
|
YYERROR;
|
33
|
r.rtableid = $5.rtableid;
|
34
|
+ r.cuid = $5.tracker;
|
35
|
j = calloc(1, sizeof(struct node_if));
|
36
|
if (j == NULL)
|
37
|
err(1, "antispoof: calloc");
|
38
|
@@ -1294,6 +1297,7 @@ antispoof : ANTISPOOF logquick antispoof_ifspc af antispoof_opts {
|
39
|
r.logif = $2.logif;
|
40
|
r.quick = $2.quick;
|
41
|
r.af = $4;
|
42
|
+ r.cuid = $5.tracker;
|
43
|
if (rule_label(&r, $5.label))
|
44
|
YYERROR;
|
45
|
r.rtableid = $5.rtableid;
|
46
|
@@ -1355,6 +1359,9 @@ antispoof_opt : label {
|
47
|
}
|
48
|
antispoof_opts.label = $1;
|
49
|
}
|
50
|
+ | TRACKER number {
|
51
|
+ antispoof_opts.tracker = $2;
|
52
|
+ }
|
53
|
| RTABLE NUMBER {
|
54
|
if ($2 < 0 || $2 > rt_tableid_max()) {
|
55
|
yyerror("invalid rtable id");
|
56
|
@@ -2064,6 +2071,8 @@ pfrule : action dir logquick interface route af proto fromto
|
57
|
if (rule_schedule(&r, $9.schedule))
|
58
|
YYERROR;
|
59
|
free($9.schedule);
|
60
|
+ if ($9.tracker)
|
61
|
+ r.cuid = $9.tracker;
|
62
|
r.flags = $9.flags.b1;
|
63
|
r.flagset = $9.flags.b2;
|
64
|
if (($9.flags.b1 & $9.flags.b2) != $9.flags.b1) {
|
65
|
@@ -2514,6 +2523,9 @@ filter_opt : USER uids {
|
66
|
filter_opts.keep.action = $1.action;
|
67
|
filter_opts.keep.options = $1.options;
|
68
|
}
|
69
|
+ | TRACKER number {
|
70
|
+ filter_opts.tracker = $2;
|
71
|
+ }
|
72
|
| FRAGMENT {
|
73
|
filter_opts.fragment = 1;
|
74
|
}
|
75
|
@@ -5743,6 +5755,7 @@ lookup(char *s)
|
76
|
{ "timeout", TIMEOUT},
|
77
|
{ "to", TO},
|
78
|
{ "tos", TOS},
|
79
|
+ { "tracker", TRACKER},
|
80
|
{ "ttl", TTL},
|
81
|
{ "upperlimit", UPPERLIMIT},
|
82
|
{ "urpf-failed", URPFFAILED},
|
83
|
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
|
84
|
index 1e957f6..d26c6ad 100644
|
85
|
--- a/sbin/pfctl/pfctl.c
|
86
|
+++ b/sbin/pfctl/pfctl.c
|
87
|
@@ -825,10 +825,17 @@ pfctl_print_rule_counters(struct pf_rule *rule, int opts)
|
88
|
(unsigned long long)(rule->bytes[0] +
|
89
|
rule->bytes[1]), (uintmax_t)rule->u_states_cur);
|
90
|
if (!(opts & PF_OPT_DEBUG))
|
91
|
+#ifdef PF_USER_INFO
|
92
|
printf(" [ Inserted: uid %u pid %u "
|
93
|
"State Creations: %-6ju]\n",
|
94
|
(unsigned)rule->cuid, (unsigned)rule->cpid,
|
95
|
(uintmax_t)rule->u_states_tot);
|
96
|
+#else
|
97
|
+ printf(" [ Inserted: pid %u "
|
98
|
+ "State Creations: %-6u]\n",
|
99
|
+ (unsigned)rule->cpid,
|
100
|
+ rule->states_tot);
|
101
|
+#endif
|
102
|
}
|
103
|
}
|
104
|
|
105
|
diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c
|
106
|
index aebb631..d316352 100644
|
107
|
--- a/sbin/pfctl/pfctl_parser.c
|
108
|
+++ b/sbin/pfctl/pfctl_parser.c
|
109
|
@@ -736,7 +736,11 @@ print_rule(struct pf_rule *r, const char *anchor_call, int verbose, int numeric)
|
110
|
int i, opts;
|
111
|
|
112
|
if (verbose)
|
113
|
+#ifdef PF_USER_INFO
|
114
|
printf("@%d ", r->nr);
|
115
|
+#else
|
116
|
+ printf("@%d(%u) ", r->nr, r->cuid);
|
117
|
+#endif
|
118
|
if (r->action == PF_MATCH)
|
119
|
printf("match");
|
120
|
else if (r->action > PF_NORDR)
|
121
|
diff --git a/sys/net/if_pflog.h b/sys/net/if_pflog.h
|
122
|
index 0faeb7d..326b551 100644
|
123
|
--- a/sys/net/if_pflog.h
|
124
|
+++ b/sys/net/if_pflog.h
|
125
|
@@ -40,10 +40,14 @@ struct pfloghdr {
|
126
|
char ruleset[PFLOG_RULESET_NAME_SIZE];
|
127
|
u_int32_t rulenr;
|
128
|
u_int32_t subrulenr;
|
129
|
+#ifdef PF_USER_INFO
|
130
|
uid_t uid;
|
131
|
pid_t pid;
|
132
|
uid_t rule_uid;
|
133
|
pid_t rule_pid;
|
134
|
+#else
|
135
|
+ u_int32_t ridentifier;
|
136
|
+#endif
|
137
|
u_int8_t dir;
|
138
|
u_int8_t pad[3];
|
139
|
};
|
140
|
diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
|
141
|
index 9ae1992..1201dfc 100644
|
142
|
--- a/sys/net/pfvar.h
|
143
|
+++ b/sys/net/pfvar.h
|
144
|
@@ -546,7 +546,11 @@ struct pf_rule {
|
145
|
u_int32_t rt_listid;
|
146
|
u_int32_t nr;
|
147
|
u_int32_t prob;
|
148
|
+#ifdef PF_USER_INFO
|
149
|
uid_t cuid;
|
150
|
+#else
|
151
|
+ u_int32_t cuid;
|
152
|
+#endif
|
153
|
pid_t cpid;
|
154
|
|
155
|
counter_u64_t states_cur;
|
156
|
@@ -1143,11 +1147,13 @@ struct pfi_kif {
|
157
|
#define PFI_IFLAG_SKIP 0x0100 /* skip filtering on interface */
|
158
|
|
159
|
struct pf_pdesc {
|
160
|
+#ifdef PF_USER_INFO
|
161
|
struct {
|
162
|
int done;
|
163
|
uid_t uid;
|
164
|
gid_t gid;
|
165
|
} lookup;
|
166
|
+#endif
|
167
|
u_int64_t tot_len; /* Make Mickey money */
|
168
|
union {
|
169
|
struct tcphdr *tcp;
|
170
|
diff --git a/sys/netpfil/pf/if_pflog.c b/sys/netpfil/pf/if_pflog.c
|
171
|
index 1efd5e2..5c22806 100644
|
172
|
--- a/sys/netpfil/pf/if_pflog.c
|
173
|
+++ b/sys/netpfil/pf/if_pflog.c
|
174
|
@@ -209,7 +209,7 @@ pflog_packet(struct pfi_kif *kif, struct mbuf *m, sa_family_t af, u_int8_t dir,
|
175
|
return (0);
|
176
|
|
177
|
bzero(&hdr, sizeof(hdr));
|
178
|
- hdr.length = PFLOG_REAL_HDRLEN;
|
179
|
+ hdr.length = PFLOG_HDRLEN;
|
180
|
hdr.af = af;
|
181
|
hdr.action = rm->action;
|
182
|
hdr.reason = reason;
|
183
|
@@ -218,13 +218,16 @@ pflog_packet(struct pfi_kif *kif, struct mbuf *m, sa_family_t af, u_int8_t dir,
|
184
|
if (am == NULL) {
|
185
|
hdr.rulenr = htonl(rm->nr);
|
186
|
hdr.subrulenr = 1;
|
187
|
+ hdr.ridentifier = rm->cuid;
|
188
|
} else {
|
189
|
hdr.rulenr = htonl(am->nr);
|
190
|
hdr.subrulenr = htonl(rm->nr);
|
191
|
+ hdr.ridentifier = rm->cuid;
|
192
|
if (ruleset != NULL && ruleset->anchor != NULL)
|
193
|
strlcpy(hdr.ruleset, ruleset->anchor->name,
|
194
|
sizeof(hdr.ruleset));
|
195
|
}
|
196
|
+#ifdef PF_USER_INFO
|
197
|
/*
|
198
|
* XXXGL: we avoid pf_socket_lookup() when we are holding
|
199
|
* state lock, since this leads to unsafe LOR.
|
200
|
@@ -239,6 +242,7 @@ pflog_packet(struct pfi_kif *kif, struct mbuf *m, sa_family_t af, u_int8_t dir,
|
201
|
hdr.pid = NO_PID;
|
202
|
hdr.rule_uid = rm->cuid;
|
203
|
hdr.rule_pid = rm->cpid;
|
204
|
+#endif
|
205
|
hdr.dir = dir;
|
206
|
|
207
|
#ifdef INET
|
208
|
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
|
209
|
index 4767882..9f0ebac 100644
|
210
|
--- a/sys/netpfil/pf/pf.c
|
211
|
+++ b/sys/netpfil/pf/pf.c
|
212
|
@@ -2763,6 +2763,7 @@ pf_match_ieee8021q_pcp(u_int8_t op, u_int8_t pcp1, u_int8_t pcp2,
|
213
|
return (pf_match(op, pcp1, pcp2, mpcp));
|
214
|
}
|
215
|
|
216
|
+#ifdef PF_USER_INFO
|
217
|
static int
|
218
|
pf_match_uid(u_int8_t op, uid_t a1, uid_t a2, uid_t u)
|
219
|
{
|
220
|
@@ -2778,6 +2779,7 @@ pf_match_gid(u_int8_t op, gid_t a1, gid_t a2, gid_t g)
|
221
|
return (0);
|
222
|
return (pf_match(op, a1, a2, g));
|
223
|
}
|
224
|
+#endif
|
225
|
|
226
|
int
|
227
|
pf_match_tag(struct mbuf *m, struct pf_rule *r, int *tag, int mtag)
|
228
|
@@ -2986,6 +2988,7 @@ pf_rule_to_actions(struct pf_rule *r, struct pf_rule_actions *a)
|
229
|
a->flags |= PFRULE_DN_IS_PIPE;
|
230
|
}
|
231
|
|
232
|
+#ifdef PF_USER_INFO
|
233
|
int
|
234
|
pf_socket_lookup(int direction, struct pf_pdesc *pd, struct mbuf *m)
|
235
|
{
|
236
|
@@ -3065,6 +3068,7 @@ pf_socket_lookup(int direction, struct pf_pdesc *pd, struct mbuf *m)
|
237
|
|
238
|
return (1);
|
239
|
}
|
240
|
+#endif
|
241
|
|
242
|
static u_int8_t
|
243
|
pf_get_wscale(struct mbuf *m, int off, u_int16_t th_off, sa_family_t af)
|
244
|
@@ -3283,12 +3287,14 @@ pf_test_rule(struct pf_rule **rm, struct pf_state **sm, int direction,
|
245
|
|
246
|
PF_RULES_RASSERT();
|
247
|
|
248
|
+#ifdef PF_USER_INFO
|
249
|
if (inp != NULL) {
|
250
|
INP_LOCK_ASSERT(inp);
|
251
|
pd->lookup.uid = inp->inp_cred->cr_uid;
|
252
|
pd->lookup.gid = inp->inp_cred->cr_groups[0];
|
253
|
pd->lookup.done = 1;
|
254
|
}
|
255
|
+#endif
|
256
|
|
257
|
switch (pd->proto) {
|
258
|
case IPPROTO_TCP:
|
259
|
@@ -3510,6 +3516,7 @@ pf_test_rule(struct pf_rule **rm, struct pf_state **sm, int direction,
|
260
|
(r->flagset & th->th_flags) != r->flags)
|
261
|
r = TAILQ_NEXT(r, entries);
|
262
|
/* tcp/udp only. uid.op always 0 in other cases */
|
263
|
+#ifdef PF_USER_INFO
|
264
|
else if (r->uid.op && (pd->lookup.done || (pd->lookup.done =
|
265
|
pf_socket_lookup(direction, pd, m), 1)) &&
|
266
|
!pf_match_uid(r->uid.op, r->uid.uid[0], r->uid.uid[1],
|
267
|
@@ -3521,6 +3528,7 @@ pf_test_rule(struct pf_rule **rm, struct pf_state **sm, int direction,
|
268
|
!pf_match_gid(r->gid.op, r->gid.gid[0], r->gid.gid[1],
|
269
|
pd->lookup.gid))
|
270
|
r = TAILQ_NEXT(r, entries);
|
271
|
+#endif
|
272
|
else if (r->ieee8021q_pcp.op &&
|
273
|
!pf_match_ieee8021q_pcp(r->ieee8021q_pcp.op,
|
274
|
r->ieee8021q_pcp.pcp[0], r->ieee8021q_pcp.pcp[1], m))
|
275
|
diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
|
276
|
index 38bb576..9b1c070 100644
|
277
|
--- a/sys/netpfil/pf/pf_ioctl.c
|
278
|
+++ b/sys/netpfil/pf/pf_ioctl.c
|
279
|
@@ -1161,7 +1161,9 @@ pfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td
|
280
|
rule->states_cur = counter_u64_alloc(M_WAITOK);
|
281
|
rule->states_tot = counter_u64_alloc(M_WAITOK);
|
282
|
rule->src_nodes = counter_u64_alloc(M_WAITOK);
|
283
|
+#ifdef PF_USER_INFO
|
284
|
rule->cuid = td->td_ucred->cr_ruid;
|
285
|
+#endif
|
286
|
rule->cpid = td->td_proc ? td->td_proc->p_pid : 0;
|
287
|
TAILQ_INIT(&rule->rpool.list);
|
288
|
|
289
|
@@ -1187,7 +1189,6 @@ pfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td
|
290
|
V_ticket_pabuf));
|
291
|
ERROUT(EBUSY);
|
292
|
}
|
293
|
-
|
294
|
tail = TAILQ_LAST(ruleset->rules[rs_num].inactive.ptr,
|
295
|
pf_rulequeue);
|
296
|
if (tail)
|
297
|
@@ -1266,8 +1267,29 @@ pfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td
|
298
|
}
|
299
|
|
300
|
rule->rpool.cur = TAILQ_FIRST(&rule->rpool.list);
|
301
|
+#ifndef PF_USER_INFO
|
302
|
+ if (rule->cuid) {
|
303
|
+ tail = TAILQ_FIRST(ruleset->rules[rs_num].active.ptr);
|
304
|
+ while ((tail != NULL) && (tail->cuid != rule->cuid))
|
305
|
+ tail = TAILQ_NEXT(tail, entries);
|
306
|
+ if (tail != NULL) {
|
307
|
+ rule->evaluations = tail->evaluations;
|
308
|
+ rule->packets[0] = tail->packets[0];
|
309
|
+ rule->packets[1] = tail->packets[1];
|
310
|
+ rule->bytes[0] = tail->bytes[0];
|
311
|
+ rule->bytes[1] = tail->bytes[1];
|
312
|
+ } else {
|
313
|
+ rule->evaluations = rule->packets[0] = rule->packets[1] =
|
314
|
+ rule->bytes[0] = rule->bytes[1] = 0;
|
315
|
+ }
|
316
|
+ } else {
|
317
|
+ rule->evaluations = rule->packets[0] = rule->packets[1] =
|
318
|
+ rule->bytes[0] = rule->bytes[1] = 0;
|
319
|
+ }
|
320
|
+#else
|
321
|
rule->evaluations = rule->packets[0] = rule->packets[1] =
|
322
|
rule->bytes[0] = rule->bytes[1] = 0;
|
323
|
+#endif
|
324
|
TAILQ_INSERT_TAIL(ruleset->rules[rs_num].inactive.ptr,
|
325
|
rule, entries);
|
326
|
ruleset->rules[rs_num].inactive.rcount++;
|
327
|
@@ -1417,7 +1439,9 @@ DIOCADDRULE_error:
|
328
|
newrule->states_cur = counter_u64_alloc(M_WAITOK);
|
329
|
newrule->states_tot = counter_u64_alloc(M_WAITOK);
|
330
|
newrule->src_nodes = counter_u64_alloc(M_WAITOK);
|
331
|
+#ifdef PF_USER_INFO
|
332
|
newrule->cuid = td->td_ucred->cr_ruid;
|
333
|
+#endif
|
334
|
newrule->cpid = td->td_proc ? td->td_proc->p_pid : 0;
|
335
|
TAILQ_INIT(&newrule->rpool.list);
|
336
|
}
|