simple examples of how to

Monday, October 3, 2011

[Kernel system function trace] What happen "ifconfig eth0 up"

what would happen if I type
$ ifconfig eth0 up

ifconfig binary uses ioctl to send message SIOCSIFFLAGS:

Then, the function trace of the above action in linux kernel is the following

[net/socket.c] sock_ioctl() called
----> sock->ops->ioctl() called

[net/ipv4/af_inet.c] inet_ioctl() called # sock->ops->ioctl == inet_ioctl

[net/ipv4/devinet.c] devinet_ioctl() called
# in this function (devinet_ioctl), we got a quite important conversion
# that we convert net (struct net) and ifname to the dev (struct net_device)
# using the function __dev_get_by_name() defined in [net/core/dev.c]

[net/core/dev.c] dev_change_flags() called
# after changing the flags, since it is up flag (interface-up event),
# this interface-up event should be notified to other "things" that are interested
# this notification is done by rtnetlink

[net/core/rtnetlink.c] rtmsg_ifinfo() called # to notify the interface-up event

[net/core/rtnetlink.c] rtnl_notify() called
# in this function, we use rtnl field in net (struct net) as the sock group
# who are interested in this interface-up event (after referred as sk)

[net/netlink/af_netlink.c] nlmsg_notify() called
# this function use either nlmsg_multicast or nlmsg_unicast, lets assume nlmsg_multicast

[include/net/netlink.h] nlmsg_multicast called()

[net/netlink/af_netlink.c] netlink_broadcast() called

[net/netlink/af_netlink.c] do_one_broadcast() called multiple times

[net/netlink/af_netlink.c] netlink_broadcast_deliver() called
# now in this function, the message packed in skb is delivered to the sk (struct sock)
# by putting skb into the sk_receive_queue field (list_head) in the sk (struct sock)

No comments:

Post a Comment