gpt4 book ai didi

更改目标ip

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:24:12 25 4
gpt4 key购买 nike

我正在尝试创建一个在特定条件下转发数据包的内核模块。现在我正在尝试做一个硬代码测试来转发在一个接口(interface)中收到的数据包并将其转发到另一个接口(interface)。在这个测试中,我从 eth0 上的 192.168.56.101 收到一个数据包,我想在 eht1 上转发这个数据包到 192.168.57.1​​03。在 eth0 中,我的 ip 是 192.168.56.102,在 eth1 中,我的 ip 是 192.168.57.1​​02。我使用的传输协议(protocol)是一个实验协议(protocol) (253)。以下代码只是我的代码的简化部分:

#define XOR_PROTOCOL 253

static unsigned int xor_pre_routing_hook(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))
{
struct iphdr *iph;
struct xorhdr *ptr;
char sip[15];
char sip2[15];

iph = ip_hdr(skb);

sprintf(sip, "%pI4", &iph->saddr);
sprintf(sip2, "%pI4", &iph->daddr);

// Check if is XOR protocol
if (iph->protocol == XOR_PROTOCOL) {
DEBUG("(Ogirinal) From %pI4 to %pI4.\n", &iph->saddr, &iph->daddr);

if (strcmp(sip, "192.168.56.101") == 0 && strcmp(sip2, "192.168.56.255") == 0) {
//iph->saddr = inet_addr("192.168.57.102");
iph->daddr = inet_addr("192.168.57.103");
DEBUG("(Modified) From %pI4 to %pI4.\n", &iph->saddr, &iph->daddr);
iph = ip_hdr(skb);
iph->check = 0;
ip_send_check (iph);
return NF_ACCEPT;
}
}
accept:
return NF_ACCEPT;
}

NF_INET_PRE_ROUTING 中的这个钩子(Hook)。我还有一个钩子(Hook),用于在 NF_INET_FORWARD 中打印源和目标 ip,但是没有数据包通过这个钩子(Hook)。

我在 virtual box 上使用 3 个 linux 虚拟机进行测试,我在每个虚拟机中启用了转发选项。在这种情况下是否可以转发数据包?我做错了什么,我该怎么做才能解决这个问题?

最佳答案

问题是广播 IP 192.168.56.255,IP 192.168.56.102 数据包被转发。

关于更改目标ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38030840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com