- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为运行 OpenWrt 的路由器编写了一个内核模块来修改所有转发的 HTTP 包中的用户代理。它在内核v4.9中运行良好,但在内核v4.14.63中无法捕获目标端口小于1024的包。
对于内核 v4.14.63,我编写了 nf_register_net_hook(&init_net, &nfho)
而不是 nf_register_hook(&nfho)
。该函数也返回0,但我只能抓取目标端口大于1024的包。我猜可能是错误使用了新参数*net造成的。所以我尝试了这个:
for_each_net(n) nf_unregister_net_hook(n, &nfho);
当我输入 insmod xmurp-test
时,它会给我:
无法插入/lib/modules/4.14.63/xmurp-test.ko
我的测试代码是这样的:
static struct nf_hook_ops nfho;
unsigned int hook_funcion(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)
{
register struct tcphdr *tcph;
register struct iphdr *iph;
// check if it is TCP package here
if(skb == 0)
return NF_ACCEPT;
iph = ip_hdr(skb);
if(iph->protocol != IPPROTO_TCP)
return NF_ACCEPT;
tcph = tcp_hdr(skb);
// debug here
printk("tcph->dest = %d", tcph->dest);
if(tcph->dest != 80)
return NF_ACCEPT;
return NF_ACCEPT;
}
static int __init hook_init(void)
{
int ret = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
struct net *n;
#endif
nfho.hook = hook_funcion;
nfho.pf = NFPROTO_IPV4;
nfho.hooknum = NF_INET_FORWARD;
nfho.priority = NF_IP_PRI_MANGLE;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
for_each_net(n)
ret += nf_register_net_hook(n, &nfho);
#else
ret = nf_register_hook(&nfho);
#endif
printk("xmurp-ua start\n");
printk("nf_register_hook returnd %d\n", ret);
return 0;
}
static void __exit hook_exit(void)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
struct net *n;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
for_each_net(n)
nf_unregister_net_hook(n, &nfho);
#else
nf_unregister_hook(&nfho);
#endif
printk("xmurp-ua stop\n");
}
module_init(hook_init);
module_exit(hook_exit);
这是我的内核日志的一部分:(未找到小于 1024 的目标端口)
[ 1596.601063] tcph->dest = 15380
[ 1596.619027] tcph->dest = 2067
[ 1596.622388] tcph->dest = 14115
[ 1596.649652] tcph->dest = 47873
[ 1596.903875] tcph->dest = 1044
[ 1596.907796] tcph->dest = 20480
[ 1596.950417] tcph->dest = 20480
[ 1596.953985] tcph->dest = 1044
[ 1597.051657] tcph->dest = 20480
[ 1597.061290] tcph->dest = 29205
[ 1597.109917] tcph->dest = 1044
[ 1597.129058] tcph->dest = 20480
[ 1597.132366] tcph->dest = 1044
[ 1597.151498] tcph->dest = 20480
[ 1597.513850] tcph->dest = 1044
[ 1597.517715] tcph->dest = 20480
[ 1597.904445] tcph->dest = 1044
[ 1597.911922] tcph->dest = 20480
[ 1598.277374] tcph->dest = 1044
[ 1598.281972] tcph->dest = 20480
[ 1598.390774] tcph->dest = 47873
[ 1598.405492] tcph->dest = 14115
[ 1598.428335] tcph->dest = 11029
[ 1598.431651] tcph->dest = 11029
[ 1598.451623] tcph->dest = 14115
[ 1598.496708] tcph->dest = 2067
[ 1598.515683] tcph->dest = 47873
[ 1598.671040] tcph->dest = 1044
[ 1598.676368] tcph->dest = 20480
[ 1598.781044] tcph->dest = 20480
[ 1598.784667] tcph->dest = 1044
[ 1598.935491] tcph->dest = 1044
[ 1598.970062] tcph->dest = 20480
[ 1598.973473] tcph->dest = 1044
[ 1598.999175] tcph->dest = 20480
[ 1599.372445] tcph->dest = 1044
[ 1599.376848] tcph->dest = 20480
[ 1599.746570] tcph->dest = 1044
[ 1599.754935] tcph->dest = 20480
[ 1600.023671] tcph->dest = 47873
[ 1600.027202] tcph->dest = 32021
[ 1600.128045] tcph->dest = 1044
最佳答案
结果表明字节顺序是关键。
// wrong
printk("tcph->dest = %d", tcph->dest);
// right
printk("tcph->dest = %d", ntohs(tcph->dest));
关于linux-kernel - 在 v4.13.x 之后使用 netfilter hooks 捕获内核模块中的所有包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54073052/
我需要从 kernel/system/do_kill.c (Minix) 将一些信息写入我的特殊日志文件(例如,/home/log.txt) . 我已经尝试过: int filedesc; filed
我正在经历 Uboot 和内核启动过程。 FDT(平面设备树)到底有什么用? 我读过的许多链接都指出,uboot 以 FDT 的形式将板和 SOC 配置信息传递给内核 https://wiki.fre
我的操作系统是Fedora 17。最近,出现内核污染警告“kernel bug at kernel/auditsc.c:1772!-abrt”:不应报告此问题(这可能是一个已知问题)。发生内核问题,但
为 Linux 编译内核模块的教程,使用不同的 Makefile 语法。 Example 1 obj-m += rpi-pwm.o Example 2 obj-m := nothing.o 有什么区别
我正在浏览 Linux 网络设备驱动程序代码,想知道是否可以从驱动程序代码中调用设备层代码。 --- a/drivers/net/ethernet/realtek/8139too.c +++ b/dr
出于工具目的,我尝试附加到 kprobe 事件,但我对 kprobe 事件不太熟悉。我读到注册的 kprobes 列表可以在 /sys/kernel/debug/kprobes/list 中找到,但是
我在其他地方使用 LinK+ 来开发 linux 内核模块。我的开发机器安装了 Linux Mint 18 操作系统,内核版本为 4.4.xx。为了进行测试,我想将内核模块部署到内核版本为 3.16.
我正在玩弄 Android Linux 内核。内核是P970 V30B内核。可用here .我想找出特定的 cmdline 参数到底做了什么。 我知道它是命令行参数,其中有一个参数我找不到它到底做了什
是否可以将 PTE 指向不同的物理页面? 假设我目前在某个进程 A 的上下文中处于内核模式,该进程当前将地址 400k 映射到物理页号。 5. 我可以将该地址 (400k) 映射到物理页号吗? 6 ?
我正在开发一个要在路由器上运行的内核模块。路由器型号为 Netgear 的 DGN2200v2。它在 MIPS 上运行 Linux 2.6.30。我的问题是,当我加载我的模块时,似乎我的 module
关闭。这个问题不符合 Stack Overflow guidelines 。它目前不接受答案。 想改进这个问题?更新问题,使其成为 Stack Overflow 的 on-topic。 6年前关闭。
在大型网格中执行的任务调用两个内核有区别吗 1. for(int i=0;i>>(MatrixA,MatrixB) } 2. dim3 dimBlock(16, 16); dim3 dimGrid(1
在 Linux 中,我生成了一个猜测 VM 并加载了另一个 Linux 实例。 VM 是通过 KVM/libvirt/qemu 生成的。 guest VM 被主机内核视为一个进程。让我们说由于某种原因
我想知道如何设置正确 MACH_TYPE或 arch_id对于内核。我搜索并找到了至少 2 个引用,其中内核会卡在“启动内核...”处。这些都给出了相同的答案。正确设置您的机器类型。但后来都没有提到如
kernel data inpage error蓝屏是一个不常见的问题,一般都是更新失败或者第三方软件冲突导致的,解决方法也非常简单,需要先安全模式进入系统,下面来看看详细的教程吧。 kern
当我用 app/console cache:clear 清除缓存时我收到错误: [Symfony\Component\DependencyInjection\Exception\ParameterNo
我正在玩 Raspberry 3,并尝试使用 U-Boot 启动 Linux 内核。 我构建了一个 Linux 内核(来自 github.com/raspberrypi)和 Busbox-Userla
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
长话短说,我一直在做一个项目,当我使用时我注意到: 1.9.3p392 :001 > `gzip` IRB::Abort: abort then interrupt! from (irb):1
我有一个服务,我在其中注入(inject) TokenStorage 并想要获取当前用户。 /** * * @Service("liip_theme.theme_request_listener"
我是一名优秀的程序员,十分优秀!