pf: add state creation/destruction notification hooks
Add callback interface for PF state lifecycle events (create, destroy, update). Used by CMM connection offload module to synchronize hardware flow tables with PF firewall state.
This commit is contained in:
parent
69d91d6eeb
commit
0e8c370df5
3 changed files with 51 additions and 0 deletions
|
|
@ -1198,6 +1198,28 @@ VNET_DECLARE(pfsync_defer_t *, pfsync_defer_ptr);
|
|||
#define V_pfsync_defer_ptr VNET(pfsync_defer_ptr)
|
||||
extern pfsync_detach_ifnet_t *pfsync_detach_ifnet_ptr;
|
||||
|
||||
/*
|
||||
* pf_notify — offload state change notification (separate from pfsync).
|
||||
*
|
||||
* Lock context for callbacks:
|
||||
* INSERT: PF_HASHROW_LOCK held, NET_EPOCH
|
||||
* UPDATE: PF_RULES_RLOCK + PF_STATE_LOCK(s) held, NET_EPOCH
|
||||
* DELETE: PF_HASHROW_LOCK held, NET_EPOCH
|
||||
*
|
||||
* Callbacks MUST NOT sleep, acquire PF_RULES_WLOCK, or re-enter the
|
||||
* pf state machine.
|
||||
*/
|
||||
typedef void pfnotify_insert_state_t(struct pf_kstate *);
|
||||
typedef void pfnotify_update_state_t(struct pf_kstate *);
|
||||
typedef void pfnotify_delete_state_t(struct pf_kstate *);
|
||||
|
||||
VNET_DECLARE(pfnotify_insert_state_t *, pfnotify_insert_state_ptr);
|
||||
#define V_pfnotify_insert_state_ptr VNET(pfnotify_insert_state_ptr)
|
||||
VNET_DECLARE(pfnotify_update_state_t *, pfnotify_update_state_ptr);
|
||||
#define V_pfnotify_update_state_ptr VNET(pfnotify_update_state_ptr)
|
||||
VNET_DECLARE(pfnotify_delete_state_t *, pfnotify_delete_state_ptr);
|
||||
#define V_pfnotify_delete_state_ptr VNET(pfnotify_delete_state_ptr)
|
||||
|
||||
void pfsync_state_export_1301(struct pfsync_state_1301 *,
|
||||
struct pf_kstate *);
|
||||
void pfsync_state_export_1400(struct pfsync_state_1400 *,
|
||||
|
|
|
|||
|
|
@ -1670,6 +1670,8 @@ pf_state_insert(struct pfi_kkif *kif, struct pfi_kkif *orig_kif,
|
|||
pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_INSERT], 1);
|
||||
if (V_pfsync_insert_state_ptr != NULL)
|
||||
V_pfsync_insert_state_ptr(s);
|
||||
if (V_pfnotify_insert_state_ptr != NULL)
|
||||
V_pfnotify_insert_state_ptr(s);
|
||||
|
||||
/* Returns locked. */
|
||||
return (0);
|
||||
|
|
@ -2457,6 +2459,8 @@ pf_unlink_state(struct pf_kstate *s)
|
|||
|
||||
if (V_pfsync_delete_state_ptr != NULL)
|
||||
V_pfsync_delete_state_ptr(s);
|
||||
if (V_pfnotify_delete_state_ptr != NULL)
|
||||
V_pfnotify_delete_state_ptr(s);
|
||||
|
||||
STATE_DEC_COUNTERS(s);
|
||||
|
||||
|
|
@ -8660,6 +8664,8 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0,
|
|||
if (s != NULL) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
}
|
||||
|
|
@ -8725,6 +8731,8 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0,
|
|||
if (s != NULL) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
}
|
||||
|
|
@ -8758,6 +8766,8 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0,
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL) {
|
||||
|
|
@ -8778,6 +8788,8 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0,
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL)
|
||||
|
|
@ -8800,6 +8812,8 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0,
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL)
|
||||
|
|
@ -9318,6 +9332,8 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL) {
|
||||
|
|
@ -9382,6 +9398,8 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL)
|
||||
|
|
@ -9412,6 +9430,8 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL) {
|
||||
|
|
@ -9439,6 +9459,8 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL)
|
||||
|
|
@ -9452,6 +9474,8 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
|
|||
if (action == PF_PASS) {
|
||||
if (V_pfsync_update_state_ptr != NULL)
|
||||
V_pfsync_update_state_ptr(s);
|
||||
if (V_pfnotify_update_state_ptr != NULL)
|
||||
V_pfnotify_update_state_ptr(s);
|
||||
r = s->rule.ptr;
|
||||
a = s->anchor.ptr;
|
||||
} else if (s == NULL)
|
||||
|
|
|
|||
|
|
@ -304,6 +304,11 @@ VNET_DEFINE(pfsync_clear_states_t *, pfsync_clear_states_ptr);
|
|||
VNET_DEFINE(pfsync_defer_t *, pfsync_defer_ptr);
|
||||
pfsync_detach_ifnet_t *pfsync_detach_ifnet_ptr;
|
||||
|
||||
/* pf_notify */
|
||||
VNET_DEFINE(pfnotify_insert_state_t *, pfnotify_insert_state_ptr);
|
||||
VNET_DEFINE(pfnotify_update_state_t *, pfnotify_update_state_ptr);
|
||||
VNET_DEFINE(pfnotify_delete_state_t *, pfnotify_delete_state_ptr);
|
||||
|
||||
/* pflog */
|
||||
pflog_packet_t *pflog_packet_ptr = NULL;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue