MCPcopy Create free account
hub / github.com/F-Stack/f-stack / enc_hhook

Function enc_hhook

freebsd/net/if_enc.c:241–317  ·  view source on GitHub ↗

* One helper hook function is used by any hook points. * + from hhook_type we can determine the packet direction: * HHOOK_TYPE_IPSEC_IN or HHOOK_TYPE_IPSEC_OUT; * + from hhook_id we can determine address family: AF_INET or AF_INET6; * + udata contains pointer to enc_softc; * + ctx_data contains pointer to struct ipsec_ctx_data. */

Source from the content-addressed store, hash-verified

239 * + ctx_data contains pointer to struct ipsec_ctx_data.
240 */
241static int
242enc_hhook(int32_t hhook_type, int32_t hhook_id, void *udata, void *ctx_data,
243 void *hdata, struct osd *hosd)
244{
245 struct ipsec_ctx_data *ctx;
246 struct enc_softc *sc;
247 struct ifnet *ifp, *rcvif;
248 struct pfil_head *ph;
249 int pdir;
250
251 sc = (struct enc_softc *)udata;
252 ifp = sc->sc_ifp;
253 if ((ifp->if_flags & IFF_UP) == 0)
254 return (0);
255
256 ctx = (struct ipsec_ctx_data *)ctx_data;
257 /* XXX: wrong hook point was used by caller? */
258 if (ctx->af != hhook_id)
259 return (EPFNOSUPPORT);
260
261 enc_bpftap(ifp, *ctx->mp, ctx->sav, hhook_type, ctx->enc, ctx->af);
262 switch (hhook_type) {
263 case HHOOK_TYPE_IPSEC_IN:
264 if (ctx->enc == IPSEC_ENC_BEFORE) {
265 /* Do accounting only once */
266 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
267 if_inc_counter(ifp, IFCOUNTER_IBYTES,
268 (*ctx->mp)->m_pkthdr.len);
269 }
270 if ((ctx->enc & V_filter_mask_in) == 0)
271 return (0); /* skip pfil processing */
272 pdir = PFIL_IN;
273 break;
274 case HHOOK_TYPE_IPSEC_OUT:
275 if (ctx->enc == IPSEC_ENC_BEFORE) {
276 /* Do accounting only once */
277 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
278 if_inc_counter(ifp, IFCOUNTER_OBYTES,
279 (*ctx->mp)->m_pkthdr.len);
280 }
281 if ((ctx->enc & V_filter_mask_out) == 0)
282 return (0); /* skip pfil processing */
283 pdir = PFIL_OUT;
284 break;
285 default:
286 return (EINVAL);
287 }
288
289 switch (hhook_id) {
290#ifdef INET
291 case AF_INET:
292 ph = V_inet_pfil_head;
293 break;
294#endif
295#ifdef INET6
296 case AF_INET6:
297 ph = V_inet6_pfil_head;
298 break;

Callers

nothing calls this directly

Calls 3

enc_bpftapFunction · 0.85
if_inc_counterFunction · 0.85
pfil_run_hooksFunction · 0.85

Tested by

no test coverage detected