network.c revision 5e97c3fcce787a5bc0f8ceef43aa3e05195b480a
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <dlezcano at fr.ibm.com>
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <net/ethernet.h>
#include <linux/rtnetlink.h>
#include <linux/if_bridge.h>
#include <nl.h>
#include <network.h>
#ifndef IFLA_LINKMODE
# define IFLA_LINKMODE 17
#endif
#ifndef IFLA_LINKINFO
# define IFLA_LINKINFO 18
#endif
#ifndef IFLA_NET_NS_PID
# define IFLA_NET_NS_PID 19
#endif
#ifndef IFLA_INFO_KIND
# define IFLA_INFO_KIND 1
#endif
#ifndef IFLA_INFO_DATA
# define IFLA_INFO_DATA 2
#endif
#ifndef VETH_INFO_PEER
# define VETH_INFO_PEER 1
#endif
struct link_req {
};
struct ip_req {
};
{
struct nl_handler nlh;
return -1;
goto out;
if (!nlmsg)
goto out;
if (!index)
goto out;
goto out;
goto out;
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
extern int device_delete(const char *name)
{
struct nl_handler nlh;
return -1;
goto out;
if (!nlmsg)
goto out;
if (!answer)
goto out;
if (!index)
goto out;
goto out;
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
{
struct nl_handler nlh;
return -1;
goto out;
if (!nlmsg)
goto out;
if (!answer)
goto out;
if (!index)
goto out;
if (err < 0)
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
{
}
int device_down(const char *name)
{
return device_set_flag(name, 0);
}
{
struct nl_handler nlh;
return -1;
goto out;
goto out;
if (!nlmsg)
goto out;
if (!answer)
goto out;
if (!index)
goto out;
goto out;
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
{
struct nl_handler nlh;
return -1;
goto out;
goto out;
if (!nlmsg)
goto out;
if (!answer)
goto out;
if (!nest1)
goto out;
goto out;
if (!nest2)
goto out;
if (!nest3)
goto out;
goto out;
goto out;
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
{
struct nl_handler nlh;
return -1;
goto out;
goto out;
if (!nlmsg)
goto out;
if (!answer)
goto out;
if (!index)
goto out;
if (!nest)
goto out;
goto out;
goto out;
goto out;
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
{
if (fd < 0)
return -errno;
return err;
}
{
char *path;
int ret;
return -1;
return ret;
}
{
}
{
}
{
char path[MAXPATHLEN];
return -1;
}
{
}
{
}
{
unsigned char *data;
char c;
int i = 0;
unsigned val;
val = 0;
c = *macaddr++;
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
else if (c >= 'A' && c <= 'F')
else {
return -1;
}
val <<= 4;
c = *macaddr;
if (isdigit(c))
val |= c - '0';
else if (c >= 'a' && c <= 'f')
else if (c >= 'A' && c <= 'F')
else if (c == ':' || c == 0)
val >>= 4;
else {
return -1;
}
if (c != 0)
macaddr++;
i++;
if (*macaddr == ':')
macaddr++;
}
return 0;
}
{
struct nl_handler nlh;
/* struct in_addr in_bcast; */
return -1;
goto out;
/* if (inet_pton(AF_INET, bcast, (void *)&in_bcast) < 0) */
/* goto out; */
if (!nlmsg)
goto out;
if (!answer)
goto out;
if (!ifindex)
goto out;
goto out;
goto out;
/* if (in_bcast.s_addr != INADDR_ANY) */
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in_bcast, */
/* sizeof(in_bcast))) */
/* goto out; */
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
{
struct nl_handler nlh;
/* struct in6_addr in6_bcast; */
return -1;
goto out;
/* if (inet_pton(AF_INET6, bcast, (void *)&in6_bcast) < 0) */
/* goto out; */
if (!nlmsg)
goto out;
if (!answer)
goto out;
if (!ifindex)
goto out;
goto out;
goto out;
/* if (in6_bcast.s6_addr != in6addr_any.s6_addr) */
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in6_bcast, */
/* sizeof(in6_bcast))) */
/* goto out; */
goto out;
err = 0;
out:
netlink_close(&nlh);
return err;
}
static int bridge_add_del_interface(const char *bridge,
{
return -1;
if (!index)
return -1;
if (fd < 0)
return -1;
return err;
}
{
}
{
}
{
int err = -1;
return -1;
}
goto err;
}
err = 0;
out:
return err;
err:
goto out;
}
{
return -1;
}
return 0;
}