是否可以修改接口索引 [英] Is it possible to modify interface index

查看:206
本文介绍了是否可以修改接口索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果内核出于某种原因决定更改接口索引,则我们的用户空间代码缓存的接口索引不会得到更新,并且会开始丢弃数据包,因为它们在用户空间中缓存的接口索引与内核中实际存在的接口索引之间不匹配.

If the kernel decides to change the interface index for some reason, our userspace code cached interface index does not gets updated and it starts dropping the packet because their is mismatch between interface index cached in userspace and what is actually present in kernel.

我已使用if_indextoname(index,interfaceName)解决此问题.内核基本上知道哪个索引映射到正确的接口名称.

I've used if_indextoname(index, interfaceName) to solve this problem. Basically kernel knows which index maps to correct interface name.

现在是我的要求:我需要测试我的代码.有没有一种方法可以模拟索引更改,以便验证代码?我有一种直觉,因为索引是内核非常特定的东西,因此只能通过调用(if_nametoindex()/etc.)进行访问,但是我们无法更改它.那么如何验证我的变更集?

Now comes my requirement: I need to test my code. Is there a way by which I can simulate index change so that I can verify my code? I have a gut feeling that since index is something which is very much particular to kernel thus it can only be accessed by calls(if_nametoindex()/etc.) but we can't change it. So how do I validate my changeset?

推荐答案

sysctl无法执行您的建议.

sysctl can't do what you are suggesting.

udev负责命名接口,即使有一些命名方案,也没有什么可以更改索引.

udev takes care of naming interfaces and even though there are a few naming schemes there is nothing to change the index.

如果您可以阅读代码,请在这里查看:

If you can read code have a look here:

http://cgit. freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20

这篇关于是否可以修改接口索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆