+static void
+esp_input_log(struct mbuf *m, struct secasvar *sav, u_int32_t spi, u_int32_t seq)
+{
+ if (net_mpklog_enabled &&
+ (sav->sah->ipsec_if->if_xflags & IFXF_MPK_LOG) == IFXF_MPK_LOG) {
+ struct tcphdr th = {};
+ u_int32_t proto_len = 0;
+ u_int8_t iphlen = 0;
+ u_int8_t proto = 0;
+
+ struct ip *inner_ip = mtod(m, struct ip *);
+ if (IP_VHL_V(inner_ip->ip_vhl) == 4) {
+ iphlen = (u_int8_t)(IP_VHL_HL(inner_ip->ip_vhl) << 2);
+ proto = inner_ip->ip_p;
+ } else if (IP_VHL_V(inner_ip->ip_vhl) == 6) {
+ struct ip6_hdr *inner_ip6 = mtod(m, struct ip6_hdr *);
+ iphlen = sizeof(struct ip6_hdr);
+ proto = inner_ip6->ip6_nxt;
+ }
+
+ if (proto == IPPROTO_TCP) {
+ if ((int)(iphlen + sizeof(th)) <= m->m_pkthdr.len) {
+ m_copydata(m, iphlen, sizeof(th), (u_int8_t *)&th);
+ }
+
+ proto_len = m->m_pkthdr.len - iphlen - (th.th_off << 2);
+ MPKL_ESP_INPUT_TCP(esp_mpkl_log_object,
+ ntohl(spi), seq,
+ ntohs(th.th_sport), ntohs(th.th_dport),
+ ntohl(th.th_seq), proto_len);
+ }
+ }
+}
+