1

저는 커널 모듈을 배우고 있으며 새로 도입했습니다. eth0의 MTU 크기를 변경하고 싶습니다. 여기 제가 작성한 모듈 프로그램이 있습니다.MTU 크기를 변경하는 Linux 커널 모듈이 작동하지 않습니다.

의도는 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); 
+0

이렇게하려면 커널 모듈이 필요하지 않습니다.이 명령을 터미널'ifconfig eth0 mtu 1000 up'에 입력하십시오. –

답변

1

당신은 어떤 실제 네트워크 장치에 할당되지 않은 구조 MTU를 설정한다. 초기화에서 로컬 변수 dev을 선언하고 필드를 변경했습니다.

먼저 변경할 네트워크 장치을 찾아야합니다. 이는 같은 __dev_get_by_name 이루어집니다 : 변경 사항이 네트워크 인터페이스에 적용됩니다

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

그 후.