mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
pf: use an enum for packet direction in divert tag
The benefit is that in the debugger you will see PF_DIVERT_MTAG_DIR_IN instead of 1 when looking at a structure. And compilation time failure if anybody sets it to a wrong value. Using "port" instead of "ndir" when assigning a port improves readability of code. Suggested by: glebius MFC after: 3 weeks X-MFC-With: fabf705f4b (cherry picked from commit c1146e6ad67fb866c2472a1cbe5609fd939fd5ef)
This commit is contained in:
parent
2f3f9c9d54
commit
3903a749c8
3 changed files with 12 additions and 6 deletions
|
|
@ -182,7 +182,7 @@ divert_packet(struct mbuf *m, bool incoming)
|
|||
(((struct ipfw_rule_ref *)(mtag+1))->info));
|
||||
} else if ((mtag = m_tag_locate(m, MTAG_PF_DIVERT, 0, NULL)) != NULL) {
|
||||
cookie = ((struct pf_divert_mtag *)(mtag+1))->idir;
|
||||
nport = htons(((struct pf_divert_mtag *)(mtag+1))->ndir);
|
||||
nport = htons(((struct pf_divert_mtag *)(mtag+1))->port);
|
||||
} else {
|
||||
m_freem(m);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -328,11 +328,17 @@ extern int (*ip_dn_ctl_ptr)(struct sockopt *);
|
|||
extern int (*ip_dn_io_ptr)(struct mbuf **, struct ip_fw_args *);
|
||||
|
||||
/* pf specific mtag for divert(4) support */
|
||||
enum { PF_DIVERT_MTAG_DIR_IN=1, PF_DIVERT_MTAG_DIR_OUT=2 };
|
||||
__enum_uint8_decl(pf_mtag_dir) {
|
||||
PF_DIVERT_MTAG_DIR_IN = 1,
|
||||
PF_DIVERT_MTAG_DIR_OUT = 2
|
||||
};
|
||||
struct pf_divert_mtag {
|
||||
uint16_t idir; // initial pkt direction
|
||||
uint16_t ndir; // a) divert(4) port upon initial diversion
|
||||
// b) new direction upon pkt re-enter
|
||||
__enum_uint8(pf_mtag_dir) idir; // initial pkt direction
|
||||
union {
|
||||
__enum_uint8(pf_mtag_dir) ndir; // a) divert(4) port upon initial diversion
|
||||
// b) new direction upon pkt re-enter
|
||||
uint16_t port; /* Initial divert(4) port */
|
||||
};
|
||||
};
|
||||
#define MTAG_PF_DIVERT 1262273569
|
||||
|
||||
|
|
|
|||
|
|
@ -8249,7 +8249,7 @@ done:
|
|||
mtag = m_tag_alloc(MTAG_PF_DIVERT, 0,
|
||||
sizeof(struct pf_divert_mtag), M_NOWAIT | M_ZERO);
|
||||
if (mtag != NULL) {
|
||||
((struct pf_divert_mtag *)(mtag+1))->ndir =
|
||||
((struct pf_divert_mtag *)(mtag+1))->port =
|
||||
ntohs(r->divert.port);
|
||||
((struct pf_divert_mtag *)(mtag+1))->idir =
|
||||
(dir == PF_IN) ? PF_DIVERT_MTAG_DIR_IN :
|
||||
|
|
|
|||
Loading…
Reference in a new issue