我正在容器中的端口 80 中运行应用程序。现在我想通过使用端口 90 来调用它,xdp 会将端口从 90 更改为 80。但是由于某种原因,我得到了任何响应,或者服务器也没有得到任何调用。这是我的 ebf 代码:
static inline unsigned short checksum(unsigned short *buf, int bufsz) {
unsigned long sum = 0;
while (bufsz > 1) {
sum += *buf;
buf++;
bufsz -= 2;
}
if (bufsz == 1) {
sum += *(unsigned char *)buf;
}
sum = (sum & 0xffff) + (sum >> 16);
sum = (sum & 0xffff) + (sum >> 16);
return ~sum;
}
int tcpfilter(struct xdp_md *ctx) {
bpf_trace_printk("got a packet\n");
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct ethhdr *eth = data;
if ((void*)eth + sizeof(*eth) <= data_end) {
struct iphdr *ip = data + sizeof(*eth);
if ((void*)ip + sizeof(*ip) <= data_end) {
if (ip->protocol == IPPROTO_TCP) {
struct tcphdr *tcp = (void*)ip + sizeof(*ip);
if ((void*)tcp + sizeof(*tcp) <= data_end) {
if (tcp->dest == ntohs(90)) {
bpf_trace_printk("tcp port 90\n");
tcp->dest = ntohs(80);
tcp->check=0;
tcp->check = checksum((unsigned short *)tcp, sizeof(struct tcphdr));
}
}
}
}
}
return XDP_PASS;
}
仅供参考,我正在使用 bcc 库并在那里创建了一个问题。任何建议将不胜感激。 https://github.com/iovisor/bcc/issues/3829
注意:我使用的是环回lo
接口。