gisi: bring Phonet interface up before telling upper layers about it

This should get kernel-assisted Phonet autoconfiguration to work (and it
shouldn't hurt in other cases). Otherwise, the upper layers will try to
send packets, which will fail. Then they will probably just time out.
This commit is contained in:
Rémi Denis-Courmont 2009-09-10 14:49:30 +03:00 committed by Aki Niemi
parent 3feaacb6ce
commit 54f61961b5
1 changed files with 18 additions and 0 deletions

View File

@ -38,6 +38,9 @@
#endif
#include "phonet.h"
#include <linux/rtnetlink.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <glib.h>
#include "netlink.h"
@ -53,6 +56,19 @@ static inline GIsiModem *make_modem(unsigned idx)
return (void *)(uintptr_t)idx;
}
static int bring_up(int fd, unsigned ifindex)
{
struct ifreq req = { .ifr_ifindex = ifindex, };
if (ioctl(fd, SIOCGIFINDEX, &req) ||
ioctl(fd, SIOCGIFFLAGS, &req))
return -errno;
req.ifr_flags |= IFF_UP | IFF_RUNNING;
if (ioctl(fd, SIOCSIFFLAGS, &req))
return -errno;
return 0;
}
/* Parser Netlink messages */
static gboolean g_pn_nl_process(GIOChannel *channel, GIOCondition cond,
gpointer data)
@ -113,6 +129,8 @@ static gboolean g_pn_nl_process(GIOChannel *channel, GIOCondition cond,
rta = RTA_NEXT(rta, len))
if (rta->rta_type == IFA_LOCAL)
memcpy(&addr, RTA_DATA(rta), 1);
if (up)
bring_up(fd, ifa->ifa_index);
self->callback(up, addr,
make_modem(ifa->ifa_index), self->opaque);
}