public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] How to change MTU?
@ 2006-05-15  6:17 蔡述宪
  2006-05-17  8:25 ` Birahim Larou Fall
  0 siblings, 1 reply; 2+ messages in thread
From: 蔡述宪 @ 2006-05-15  6:17 UTC (permalink / raw)
  To: ecos-discuss

Hello, everyone!

  I am now implementing a router using eCos. I want to change the MTU 
of one of my two network interfaces. I tried to do that using the 
socket to kernel routing table, here is my code:

    //for route add and delete	
    u_int32_t g,m,d;

    int routes;
    struct {
                struct rt_msghdr	hdr;
		struct sockaddr_in	dst;
		struct sockaddr_in	gway;
		struct sockaddr_in	mask;
		} rtmsg;	

    	if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
		diag_printf("Error: route socket\n");
	}

  //change route for MTU of eth1

	g = 0x64300100;
	m = 0xFFFFFF00;
	d = 0x64300100;
	g = htonl(g);
	m = htonl(m);
	d = htonl(d);
	
	memset(&rtmsg, 0, sizeof(rtmsg));
	
	rtmsg.hdr.rtm_type = RTM_CHANGE;
	rtmsg.hdr.rtm_flags = RTF_UP | RTF_HOST |RTF_STATIC;
	rtmsg.hdr.rtm_version = RTM_VERSION;
	rtmsg.hdr.rtm_seq = ++rtm_seq;
	rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
	rtmsg.hdr.rtm_rmx.rmx_locks = 0;
	rtmsg.hdr.rtm_rmx.rmx_mtu = 1000;	
	rtmsg.dst.sin_len = sizeof(rtmsg.dst);
	rtmsg.dst.sin_family = AF_INET;
	rtmsg.dst.sin_addr.s_addr = d;
	rtmsg.gway.sin_len = sizeof(rtmsg.gway);
	rtmsg.gway.sin_family = AF_INET;
	rtmsg.gway.sin_addr.s_addr = g;
	rtmsg.mask.sin_len = sizeof(rtmsg.dst);
	rtmsg.mask.sin_family = AF_INET;
	rtmsg.mask.sin_addr.s_addr = m;
	rtmsg.hdr.rtm_msglen = sizeof(rtmsg);


	if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) {
		diag_printf("Error:route change failed\n");
	}
	
	close(routes);


  It seems that the write operation is successful, because I got no 
error message. But the MTU of my interface didn't change after that.
  Following is the output from show_network_tables():


Routing tables
Destination     Gateway         Mask            Flags    Interface
100.48.1.0      100.48.1.0      255.255.255.0   U        eth1
100.48.1.2      100.48.1.2                      UH       eth0
127.0.0.0       127.0.0.1       255.0.0.0       UG       lo0
127.0.0.1       127.0.0.1                       UH       lo0
162.105.75.0    162.105.75.0    255.255.255.0   U        eth0
162.105.78.0    100.48.1.2      255.255.255.0   UGS      eth1
Interface statistics
eth0    IP: 162.105.75.1, Broadcast: 162.105.75.255, Netmask: 
255.255.255.0
        UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
eth1    IP: 100.48.1.1, Broadcast: 100.48.1.255, Netmask: 255.255.255.0
        UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
lo0     IP: 127.0.0.1, Broadcast: 127.0.0.1, Netmask: 255.0.0.0
        UP LOOPBACK RUNNING MULTICAST MTU: 16384, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0


Why the MTU change didn't take effect? The MTU of eth1 is still 1500 
but not 1000. Is there something wrong with my code? 

Anybody done similar operation before? Thank you very much for your 
suggestion!


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ECOS] How to change MTU?
  2006-05-15  6:17 [ECOS] How to change MTU? 蔡述宪
@ 2006-05-17  8:25 ` Birahim Larou Fall
  0 siblings, 0 replies; 2+ messages in thread
From: Birahim Larou Fall @ 2006-05-17  8:25 UTC (permalink / raw)
  To: 蔡述宪; +Cc: ecos-discuss

Why you don't use ioctl  command  with SIOCSIFMTU(arg2)  as command to 
change  MTU. See " if_ethersubr.c" in freebsd sources.
You have to fill the ifreq struct (for the interface you want to change 
the MTU)

Fall Birahim
Digital TV Firmware Engineer
Elsys Design for SCM Microsystems
La Ciotat - France
+33 (0)4 42 83 87 31
Mobile :  +33 (0)6 61 40 94 81
bfall@scmmicro.com



蔡述宪 <caishuxian@water.pku.edu.cn> 
Sent by: ecos-discuss-owner@ecos.sourceware.org
15/05/2006 08:17

To
ecos-discuss@sources.redhat.com
cc

Subject
[ECOS] How to change MTU?






Hello, everyone!

  I am now implementing a router using eCos. I want to change the MTU 
of one of my two network interfaces. I tried to do that using the 
socket to kernel routing table, here is my code:

    //for route add and delete 
    u_int32_t g,m,d;

    int routes;
    struct {
                struct rt_msghdr                 hdr;
                                 struct sockaddr_in              dst;
                                 struct sockaddr_in              gway;
                                 struct sockaddr_in              mask;
                                 } rtmsg; 

                 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
                                 diag_printf("Error: route socket\n");
                 }

  //change route for MTU of eth1

                 g = 0x64300100;
                 m = 0xFFFFFF00;
                 d = 0x64300100;
                 g = htonl(g);
                 m = htonl(m);
                 d = htonl(d);
 
                 memset(&rtmsg, 0, sizeof(rtmsg));
 
                 rtmsg.hdr.rtm_type = RTM_CHANGE;
                 rtmsg.hdr.rtm_flags = RTF_UP | RTF_HOST |RTF_STATIC;
                 rtmsg.hdr.rtm_version = RTM_VERSION;
                 rtmsg.hdr.rtm_seq = ++rtm_seq;
                 rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | 
RTA_NETMASK;
                 rtmsg.hdr.rtm_rmx.rmx_locks = 0;
                 rtmsg.hdr.rtm_rmx.rmx_mtu = 1000; 
                 rtmsg.dst.sin_len = sizeof(rtmsg.dst);
                 rtmsg.dst.sin_family = AF_INET;
                 rtmsg.dst.sin_addr.s_addr = d;
                 rtmsg.gway.sin_len = sizeof(rtmsg.gway);
                 rtmsg.gway.sin_family = AF_INET;
                 rtmsg.gway.sin_addr.s_addr = g;
                 rtmsg.mask.sin_len = sizeof(rtmsg.dst);
                 rtmsg.mask.sin_family = AF_INET;
                 rtmsg.mask.sin_addr.s_addr = m;
                 rtmsg.hdr.rtm_msglen = sizeof(rtmsg);


                 if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) {
                                 diag_printf("Error:route change 
failed\n");
                 }
 
                 close(routes);


  It seems that the write operation is successful, because I got no 
error message. But the MTU of my interface didn't change after that.
  Following is the output from show_network_tables():


Routing tables
Destination     Gateway         Mask            Flags    Interface
100.48.1.0      100.48.1.0      255.255.255.0   U        eth1
100.48.1.2      100.48.1.2                      UH       eth0
127.0.0.0       127.0.0.1       255.0.0.0       UG       lo0
127.0.0.1       127.0.0.1                       UH       lo0
162.105.75.0    162.105.75.0    255.255.255.0   U        eth0
162.105.78.0    100.48.1.2      255.255.255.0   UGS      eth1
Interface statistics
eth0    IP: 162.105.75.1, Broadcast: 162.105.75.255, Netmask: 
255.255.255.0
        UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
eth1    IP: 100.48.1.1, Broadcast: 100.48.1.255, Netmask: 255.255.255.0
        UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
lo0     IP: 127.0.0.1, Broadcast: 127.0.0.1, Netmask: 255.0.0.0
        UP LOOPBACK RUNNING MULTICAST MTU: 16384, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0


Why the MTU change didn't take effect? The MTU of eth1 is still 1500 
but not 1000. Is there something wrong with my code? 

Anybody done similar operation before? Thank you very much for your 
suggestion!


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-05-17  8:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-15  6:17 [ECOS] How to change MTU? 蔡述宪
2006-05-17  8:25 ` Birahim Larou Fall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).