[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: nslu2: two devices: one by default



En/na Lennart Sorensen ha escrit:


'ethtool' or 'ip link' should be able to tell you if a link is up or down.
A clever tool would subscribe to netlink and get notifications of link
state changes, but that probably isn't necesary.

I'm planned to write a daemon which change route table according with the ip link state of eth0. I have two alternatives: use ip link and see periodically the state of link of eth0 and use netlink. I think the best it's the second (in the first case I have to wait one hour or one minute.... for recover eth0 connection after plug).

Can you help me writting it?
In the man page of netlink, we could follow:

The following example creates a NETLINK_ROUTE netlink socket which will
listen to the RTMGRP_LINK (network interface create/delete/up/down
events) and RTMGRP_IPV4_IFADDR (IPv4 addresses add/delete events) mul‐
ticast groups.

struct sockaddr_nl sa;

memset(&sa, 0, sizeof(sa));
snl.nl_family = AF_NETLINK;
snl.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;

fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
bind(fd, (struct sockaddr*)&sa, sizeof(sa));

Is this that we want? Sorry but I'm not clear with this documentation.

I simply want script that:
- get notification via netlink of up/down changes of eth0
- run

	ip route del default via 10.200.16.1 dev eth0
	ip route del 10.200.64.0/20 dev eth0  proto kernel  scope link  src 10.200.65.12

if eth0 link is down
- and
	ip route add 10.200.64.0/20 dev eth0  proto kernel  scope link  src 10.200.65.12
	ip route add default via 10.200.16.1 dev eth0
if it's come back.



Thanks for the annoying,
Xan.


Reply to: