public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: 蔡述宪 <caishuxian@water.pku.edu.cn>
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] How to change MTU?
Date: Mon, 15 May 2006 06:17:00 -0000	[thread overview]
Message-ID: <199acfa199d194.199d194199acfa@pku.edu.cn> (raw)

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

             reply	other threads:[~2006-05-15  6:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-15  6:17 蔡述宪 [this message]
2006-05-17  8:25 ` Birahim Larou Fall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199acfa199d194.199d194199acfa@pku.edu.cn \
    --to=caishuxian@water.pku.edu.cn \
    --cc=ecos-discuss@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).