rtnl.c revision 5e97c3fcce787a5bc0f8ceef43aa3e05195b480a
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/*
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * lxc: linux Container library
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen *
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * (C) Copyright IBM Corp. 2007, 2008
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen *
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * Authors:
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * Daniel Lezcano <dlezcano at fr.ibm.com>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen *
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * This library is free software; you can redistribute it and/or
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * modify it under the terms of the GNU Lesser General Public
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * License as published by the Free Software Foundation; either
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * version 2.1 of the License, or (at your option) any later version.
f7423cbbd9dea363a5df18ebb96da055a977ae79Timo Sirainen *
2cd2518bab14292a67cf8a490b58ab9ef89879daTimo Sirainen * This library is distributed in the hope that it will be useful,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen * Lesser General Public License for more details.
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen *
6ec925f52d04ec8700e47cb005bd7ddc65ac5614Timo Sirainen * You should have received a copy of the GNU Lesser General Public
c60178b2610a9b193ff72aa18448398ef72529a1Timo Sirainen * License along with this library; if not, write to the Free Software
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include <string.h>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include <stdio.h>
cf2e6953d03a1c22f272ec19432fc03c136ac1bbTimo Sirainen#include <sys/socket.h>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include <stdlib.h>
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen#include <errno.h>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include <unistd.h>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include <linux/netlink.h>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include <linux/rtnetlink.h>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include <nl.h>
617e13833c798435e2be425b99c27ecaad1b8393Timo Sirainen#include <rtnl.h>
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenextern int rtnetlink_open(struct rtnl_handler *handler)
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen{
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen return netlink_open(&handler->nlh, NETLINK_ROUTE);
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen}
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenextern int rtnetlink_close(struct rtnl_handler *handler)
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen{
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen return netlink_close(&handler->nlh);
f7423cbbd9dea363a5df18ebb96da055a977ae79Timo Sirainen}
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainenextern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg)
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen{
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen return netlink_rcv(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen}
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenextern int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg)
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen{
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen return netlink_send(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen}
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainenextern int rtnetlink_transaction(struct rtnl_handler *handler,
f7423cbbd9dea363a5df18ebb96da055a977ae79Timo Sirainen struct rtnlmsg *request, struct rtnlmsg *answer)
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen{
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen return netlink_transaction(&handler->nlh, (struct nlmsg *)&request->nlmsghdr,
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen (struct nlmsg *)&answer->nlmsghdr);
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen}
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainenextern struct rtnlmsg *rtnlmsg_alloc(size_t size)
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen{
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen/* size_t len = NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct rtnlmsghdr))) + size; */
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen/* return (struct rtnlmsg *)nlmsg_alloc(len); */
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen return NULL;
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen}
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenextern void rtnlmsg_free(struct rtnlmsg *rtnlmsg)
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen{
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen free(rtnlmsg);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen}
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen