- 论坛徽章:
- 36
|
大家一般是调用什么 API 获取 tcp header 的。
看了一下内核代码,好像有两种实现方式。
一是类似于xt_socket.c 中,示例如下:- tproto = ipv6_find_hdr(skb, &thoff, -1, NULL);
- if (tproto < 0) {
- pr_debug("unable to find transport header in IPv6 packet, dropping\n");
- return NF_DROP;
- }
- if (tproto == IPPROTO_UDP || tproto == IPPROTO_TCP) {
- hp = skb_header_pointer(skb, thoff,
- sizeof(_hdr), &_hdr);
复制代码 先获取到 IPv6 中四层的协议号,四层头部的偏移 thoff,然后再调用 skb_header_pointer 获取四层头部指针。
此外,还有一种获取四层头部偏移的方法,见 xt_TCPOPTSTRIP.c 中- static unsigned int
- tcpoptstrip_tg6(struct sk_buff *skb, const struct xt_action_param *par)
- {
- struct ipv6hdr *ipv6h = ipv6_hdr(skb);
- int tcphoff;
- u_int8_t nexthdr;
- nexthdr = ipv6h->nexthdr;
- tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr);
- if (tcphoff < 0)
- return NF_DROP;
- return tcpoptstrip_mangle_packet(skb, par->targinfo, tcphoff,
- sizeof(*ipv6h) + sizeof(struct tcphdr));
- }
复制代码 相当于有中获取四层头部偏移的 API:
* ipv6_find_hdr
* ipv6_skip_exthdr
大家一般是怎么用的,欢迎分享一下。
|
|