rtmon_bsd.c revision 23bcfa32fddbe29a8c4c40d3bcfa4693a555c177
/* $Id$ */
/** @file
* NAT Network - IPv6 default route monitor for BSD routing sockets.
*/
/*
* Copyright (C) 2013-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#define LOG_GROUP LOG_GROUP_NAT_SERVICE
#include "proxy.h"
#include <errno.h>
#include <string.h>
#include <unistd.h>
/**
* Query IPv6 routing table - BSD routing sockets version.
*
* We don't actually monitor the routing socket for updates, and
* instead query the kernel each time.
*
* We take a shortcut and don't read the reply to our RTM_GET - if
* there's no default IPv6 route, write(2) will fail with ESRCH
* synchronously. In theory it may fail asynchronously and we should
* wait for the RTM_GET reply and check rt_msghdr::rtm_errno.
*
* KAME code in *BSD maintains internally a list of default routers
* that it learned from RAs, and installs only one of them into the
* routing table (actually, I'm not sure if BSD routing table can
* handle multiple routes to the same destination). One side-effect
* of this is that when manually configured route (e.g. teredo) is
* deleted, the system will lose its default route even when KAME IPv6
* has default router(s) in its internal list. Next RA will force the
* update, though.
*
* Solaris does expose multiple routes in the routing table and
* replies to RTM_GET with "default default".
*/
int
rtmon_get_defaults(void)
{
int rtsock;
struct req {
struct sockaddr_in6 dst;
struct sockaddr_in6 mask;
struct sockaddr_dl ifp;
} req;
if (rtsock < 0) {
DPRINTF0(("rtmon: failed to create routing socket\n"));
return -1;
}
#if HAVE_SA_LEN
#endif
#if HAVE_SA_LEN
#endif
#if HAVE_SA_LEN
#endif
if (nsent < 0) {
/* there's no default route */
return 0;
}
else {
DPRINTF0(("rtmon: failed to send RTM_GET\n"));
return -1;
}
}
return 1;
}