Commit ba315472 authored by Gilles Chanteperdrix's avatar Gilles Chanteperdrix
Browse files

rtnet/ioctl: allow checking link state

Use the IFF_RUNNING bit in the flags returned by the SIOCGIFFLAGS ioctl,
like Linux SIOCGIFFLAGS ioctl.
parent 92df665f
......@@ -55,6 +55,10 @@ enum rtnet_link_state {
__RTNET_LINK_STATE_PRESENT,
__RTNET_LINK_STATE_NOCARRIER,
};
#define RTNET_LINK_STATE_XOFF (1 << __RTNET_LINK_STATE_XOFF)
#define RTNET_LINK_STATE_START (1 << __RTNET_LINK_STATE_START)
#define RTNET_LINK_STATE_PRESENT (1 << __RTNET_LINK_STATE_PRESENT)
#define RTNET_LINK_STATE_NOCARRIER (1 << __RTNET_LINK_STATE_NOCARRIER)
/***
* rtnet_device
......
......@@ -644,7 +644,7 @@ int rtdev_open(struct rtnet_device *rtdev)
ret = rtdev->open(rtdev);
if ( !ret ) {
rtdev->flags |= (IFF_UP | IFF_RUNNING);
rtdev->flags |= IFF_UP;
set_bit(__RTNET_LINK_STATE_START, &rtdev->link_state);
} else
rtdev_dereference(rtdev);
......
......@@ -210,6 +210,13 @@ static int rtnet_core_ioctl(struct rtnet_device *rtdev, unsigned int request,
cmd.args.info.broadcast_ip = rtdev->broadcast_ip;
cmd.args.info.mtu = rtdev->mtu;
cmd.args.info.flags = rtdev->flags;
if ((cmd.args.info.flags & IFF_UP)
&& (rtdev->link_state
& (RTNET_LINK_STATE_PRESENT
| RTNET_LINK_STATE_NOCARRIER))
== RTNET_LINK_STATE_PRESENT)
cmd.args.info.flags |= IFF_RUNNING;
memcpy(cmd.args.info.dev_addr, rtdev->dev_addr, MAX_ADDR_LEN);
mutex_unlock(&rtdev->nrt_lock);
......
......@@ -242,7 +242,7 @@ int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, void *arg)
for (i = 1; i <= MAX_RT_DEVICES; i++) {
rtdev = rtdev_get_by_index(i);
if (rtdev != NULL) {
if ((rtdev->flags & IFF_RUNNING) == 0) {
if ((rtdev->flags & IFF_UP) == 0) {
rtdev_dereference(rtdev);
continue;
}
......@@ -288,6 +288,12 @@ int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, void *arg)
case SIOCGIFFLAGS:
ifr->ifr_flags = rtdev->flags;
if ((ifr->ifr_flags & IFF_UP)
&& (rtdev->link_state
& (RTNET_LINK_STATE_PRESENT
| RTNET_LINK_STATE_NOCARRIER))
== RTNET_LINK_STATE_PRESENT)
ifr->ifr_flags |= IFF_RUNNING;
break;
case SIOCGIFHWADDR:
......
......@@ -290,7 +290,7 @@ void do_display(int print_flags)
ret = ioctl(f, IOC_RT_IFINFO, &cmd);
if (ret == 0) {
if (((print_flags & PRINT_FLAG_INACTIVE) != 0) ||
((cmd.args.info.flags & IFF_RUNNING) != 0))
((cmd.args.info.flags & IFF_UP) != 0))
print_dev();
} else if (errno != ENODEV) {
perror("ioctl");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment