디버깅/리눅스2010. 4. 28. 15:20
반응형

Hi friends:
   I read the snull code in chapter 17 of Linux Device Driver edition
3, compiled the code in 2.6.23 kernel, and download the code at
http://www.cs.fsu.edu/~baker/devices/lxr/http/source/ldd-examples/snull/
to compile at 2.6.24.3 kernel, and every thing is OK. Then I run the
snull_load script, both(in two kernels) meet error.

The probelm is: sn0 or sn1 are away in DOWN status, IF use ifconfig or
write test program via ioctl to make sn0/1 UP, will cause "Invalid
argument" error.


Is that anything wrong?


Below is the process:


1) compiled
ylin@ylin:~/program/modules/snull/2.6.25$ make
echo KERNELDIR = /lib/modules/2.6.24.3/build
KERNELDIR = /lib/modules/2.6.24.3/build
make -C /lib/modules/2.6.24.3/build M=/home/ylin/program/modules/snull/
2.6.25 modules
make[1]: Entering directory `/usr/src/linux-source-2.6.24'
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-source-2.6.24'
ylin@ylin:~/program/modules/snull/2.6.25$


2) insmod snull.ko
ylin@ylin:~/program/modules/snull/2.6.25$ sudo ./snull_load
SIOCSIFFLAGS: Invalid argument
SIOCSIFFLAGS: Invalid argument
SIOCSIFFLAGS: Invalid argument
SIOCSIFFLAGS: Invalid argument


Met problem here.


3) then I use ifconfig to check its status
ylin@ylin:~/program/modules/snull/2.6.25$ ifconfig -a
sn0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:
255.255.255.0
          BROADCAST NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


sn1       Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:
255.255.255.0
          BROADCAST NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


From the output, IP addressed are set but their status is NO UP.
So I use ifconfig sn0 up to configure it as step 4)


4) ifconfig sn0 up
ylin@ylin:~/program/modules/snull/2.6.25$ sudo ifconfig sn0 up
SIOCSIFFLAGS: Invalid argument           <<<<--------error here


I found the sn0/1 are aways in down status, How I can change it to UP
status?  For that, I write a test code to do so.


5) test code and testing


code as below:
---------------test.c------------------------
#include <sys/socket.h>
#include <linux/in.h>
#include <stdio.h>
#include <net/if.h>
#include <string.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>


int main()
{
    int fd;
    if((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0 ) {
        perror("socket");
        return 1;
    }


    struct ifreq req;
    strcpy(req.ifr_name, "sn0");
    if(ioctl(fd, SIOCGIFFLAGS, &req) == -1) {
        perror("ioctl get");
        return 1;
    }


    printf("%x\n", req.ifr_flags);
    req.ifr_flags |= IFF_UP;
    printf("%x\n", req.ifr_flags);


    if(ioctl(fd, SIOCSIFFLAGS, &req) == -1) {
        perror("ioctl set");
        return 1;
    }


    return 0;

 

}


--------------------------------------

compile it:
ylin@ylin:~/program/modules/snull/2.6.25$ gcc -Wall -g -o test test.c


Run it:
ylin@ylin:~/program/modules/snull/2.6.25$ sudo ./test
1082
1083
ioctl set: Invalid argument      <<<<<---set UP failure.


Why snull can run in my system properly? Is that something wrong in my
Ubuntu.


Best Regard...
Ivan.

 


    작성자에게 답글     전달        스팸 신고
스팸으로 신고 중
메시지 신고 완료
    게시물 평가:  Text for clearing space
  

  

  
 

메시지를 게시하려면 그룹에 가입해야 합니다.
메시지를 게시하려면 먼저 해당 그룹에 가입하셔야 합니다.
게시하기 전에 가입 설정 페이지에서 닉네임을 업데이트하세요.
메시지를 게시할 수 있는 권한이 없습니다.

    
  
David Schwartz    프로필 보기   한국어로 번역 번역됨(원문 보기) 
  추가 옵션 2009년3월16일, 오후8시54분 

뉴스그룹: comp.os.linux.development.system
보낸사람: David Schwartz <dav...@webmaster.com>
날짜: Mon, 16 Mar 2009 04:54:24 -0700 (PDT)
현지시간: 2009년3월16일(월) 오후8시54분
제목: Re: Does anyone meet problem on snull code (LDD3)?
작성자에게 답글 | 전달 | 인쇄 | 개별 메시지 | 원문 보기 | 메시지 신고 | 작성자의 메시지 찾기
On Mar 16, 4:35 am, Ivan <linyongt...@gmail.com> wrote:


> sn0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00
>           inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:
> 255.255.255.0
>           inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:
> 255.255.255.0


Umm, sn0 is set to 192.168.0.1/24 and sn1 is set to 192.168.1.1/24.
They are not on in the same network and so can't be directly
connected. Unless I'm remembering incorrectly, bringing the snull
interfaces up attempts to directly connect them to each other.

DS

 


    작성자에게 답글     전달        스팸 신고
스팸으로 신고 중
메시지 신고 완료
    게시물 평가:  Text for clearing space
  

  

  
 

메시지를 게시하려면 그룹에 가입해야 합니다.
메시지를 게시하려면 먼저 해당 그룹에 가입하셔야 합니다.
게시하기 전에 가입 설정 페이지에서 닉네임을 업데이트하세요.
메시지를 게시할 수 있는 권한이 없습니다.

    
  
Ivan    프로필 보기   한국어로 번역 번역됨(원문 보기) 
  추가 옵션 2009년3월17일, 오후8시16분 

뉴스그룹: comp.os.linux.development.system
보낸사람: Ivan <linyongt...@gmail.com>
날짜: Tue, 17 Mar 2009 04:16:19 -0700 (PDT)
현지시간: 2009년3월17일(화) 오후8시16분
제목: Re: Does anyone meet problem on snull code (LDD3)?
작성자에게 답글 | 전달 | 인쇄 | 개별 메시지 | 원문 보기 | 메시지 신고 | 작성자의 메시지 찾기
On Mar 16, 7:54 pm, David Schwartz <dav...@webmaster.com> wrote:


> On Mar 16, 4:35 am, Ivan <linyongt...@gmail.com> wrote:

> > sn0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00
> >           inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:
> > 255.255.255.0
> >           inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:
> > 255.255.255.0


> Umm, sn0 is set to 192.168.0.1/24 and sn1 is set to 192.168.1.1/24.
> They are not on in the same network and so can't be directly
> connected. Unless I'm remembering incorrectly, bringing the snull
> interfaces up attempts to directly connect them to each other.


> DS

 

  snull_load script setup the IP address for each sn, see bellow. In
LDD3 book, the local1 and local2 is in different network.

  1 #!/bin/sh
  2
  3 export PATH=/sbin:/bin
  4
  5 # Use a pathname, as new modutils don't look in the current dir by
default
  6 insmod ./snull.ko $*
  7 ifconfig sn0 local0
  8 ifconfig sn1 local1


Why sn0/1 device can't be set IFF_UP flags by ioctl? What happen on
this. I want to trace the ioctl function calling chain in kernel, but
I didn't know HOWTO.


Thanks for your information.
Ivan

 


    작성자에게 답글     전달        스팸 신고
스팸으로 신고 중
메시지 신고 완료
    게시물 평가:  Text for clearing space
  

  

  
 

메시지를 게시하려면 그룹에 가입해야 합니다.
메시지를 게시하려면 먼저 해당 그룹에 가입하셔야 합니다.
게시하기 전에 가입 설정 페이지에서 닉네임을 업데이트하세요.
메시지를 게시할 수 있는 권한이 없습니다.

    
  
lyad...@gmail.com    프로필 보기   한국어로 번역 번역됨(원문 보기) 
  추가 옵션 2009년5월6일, 오후6시11분 

뉴스그룹: comp.os.linux.development.system
보낸사람: lyad...@gmail.com
날짜: Wed, 6 May 2009 02:11:13 -0700 (PDT)
현지시간: 2009년5월6일(수) 오후6시11분
제목: Re: Does anyone meet problem on snull code (LDD3)?
작성자에게 답글 | 전달 | 인쇄 | 개별 메시지 | 원문 보기 | 메시지 신고 | 작성자의 메시지 찾기
Ivan:

 

- 원본 텍스트 숨기기 -
- 원본 텍스트 보기 -

> On Mar 16, 7:54 pm, David Schwartz <dav...@webmaster.com> wrote:
> > On Mar 16, 4:35 am, Ivan <linyongt...@gmail.com> wrote:

> > > sn0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00
> > >           inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:
> > > 255.255.255.0
> > >           inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:
> > > 255.255.255.0


> > Umm, sn0 is set to 192.168.0.1/24 and sn1 is set to 192.168.1.1/24.
> > They are not on in the same network and so can't be directly
> > connected. Unless I'm remembering incorrectly, bringing the snull
> > interfaces up attempts to directly connect them to each other.


> > DS


>   snull_load script setup the IP address for each sn, see bellow. In
> LDD3 book, the local1 and local2 is in different network.


>   1 #!/bin/sh
>   2
>   3 export PATH=/sbin:/bin
>   4
>   5 # Use a pathname, as new modutils don't look in the current dir by
> default
>   6 insmod ./snull.ko $*
>   7 ifconfig sn0 local0
>   8 ifconfig sn1 local1


> Why sn0/1 device can't be set IFF_UP flags by ioctl? What happen on
> this. I want to trace the ioctl function calling chain in kernel, but
> I didn't know HOWTO.


> Thanks for your information.
> Ivan

 

I have the same problem, but after I assign mac address for sn0,sn1:
  ifconfig sn0 hw ether 00:01:02:03:04:05
  ifconfig sn1 hw ether 00:01:02:03:04:06
problem disappeared.

 

반응형
Posted by pmj0403