1

私はカーネルモジュールを学んでおり、それに慣れていません。eth0 の MTU サイズを変更したい。これが私が書いたモジュールプログラムです。

意図は eth0 の MTU サイズを 1000 に変更することですが、変更されません。何が欠けているのか、誰でも教えてもらえますか。アプローチ自体が間違っている場合は、正しい方向に向けてもらえますか?

#include <linux/module.h>       
#include <linux/kernel.h>       
#include <linux/init.h>         
#include <linux/etherdevice.h>
#include <linux/netdevice.h>

static int __init hello_2_init(void)
{
        printk(KERN_INFO "Hello, world 2\n");

        struct net_device dev;
        eth_change_mtu(&dev,1000); //calling eth_change_mtu
        return 0;
}

static void __exit hello_2_exit(void)
{
        printk(KERN_INFO "Goodbye, world 2\n");
}


int eth_change_mtu(struct net_device *dev, int new_mtu)
{
        dev->mtu = new_mtu;
        printk(KERN_INFO "New MTU is %d",new_mtu);
        return 0;
}

module_init(hello_2_init);
module_exit(hello_2_exit);
4

1 に答える 1

1

実際のネットワーク デバイスに割り当てられていない構造に MTU を設定しています。init でローカル変数を宣言しdevてから、そのフィールドを変更しました。

まず、変更するネットワーク デバイスを見つける必要があります。これは__dev_get_by_name次のように行われます。

struct net_device *dev = __dev_get_by_name("eth0");

その後、変更がネットワーク インターフェイスに適用されます。

于 2014-01-29T11:11:33.550 に答える