[PATCh TAKE 2] [IPROUTE2] Add addrlabel sub-command.
Signed-off-by: YOSHIFUJI Hideaki [EMAIL PROTECTED] --- diff --git a/ip/Makefile b/ip/Makefile index b427d58..d908817 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -1,4 +1,4 @@ -IPOBJ=ip.o ipaddress.o iproute.o iprule.o \ +IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o \ rtm_map.o iptunnel.o ip6tunnel.o tunnel.o ipneigh.o ipntable.o iplink.o \ ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o \ ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o \ diff --git a/ip/ip.c b/ip/ip.c index aeb8c68..c4c773f 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -46,8 +46,8 @@ static void usage(void) fprintf(stderr, Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n ip [ -force ] [-batch filename\n -where OBJECT := { link | addr | route | rule | neigh | ntable | tunnel |\n - maddr | mroute | monitor | xfrm }\n +where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |\n + tunnel | maddr | mroute | monitor | xfrm }\n OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n -f[amily] { inet | inet6 | ipx | dnet | link } |\n -o[neline] | -t[imestamp] }\n); @@ -64,6 +64,7 @@ static const struct cmd { int (*func)(int argc, char **argv); } cmds[] = { { address,do_ipaddr }, + { addrlabel, do_ipaddrlabel }, { maddress, do_multiaddr }, { route, do_iproute }, { rule, do_iprule }, diff --git a/ip/ip_common.h b/ip/ip_common.h index 39f2507..1bbd50d 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -4,6 +4,9 @@ extern int print_linkinfo(const struct sockaddr_nl *who, extern int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); +extern int print_addrlabelinfo(const struct sockaddr_nl *who, + struct nlmsghdr *n, + void *arg); extern int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); extern int print_ntable(const struct sockaddr_nl *who, @@ -23,6 +26,7 @@ extern int print_prefix(const struct sockaddr_nl *who, extern int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); extern int do_ipaddr(int argc, char **argv); +extern int do_ipaddrlabel(int argc, char **argv); extern int do_iproute(int argc, char **argv); extern int do_iprule(int argc, char **argv); extern int do_ipneigh(int argc, char **argv); diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c new file mode 100644 index 000..1c873e9 --- /dev/null +++ b/ip/ipaddrlabel.c @@ -0,0 +1,260 @@ +/* + * ipaddrlabel.c ip addrlabel + * + * Copyright (C)2007 USAGI/WIDE Project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Based on iprule.c. + * + * Authors:YOSHIFUJI Hideaki [EMAIL PROTECTED] + * + */ + +#include stdio.h +#include stdlib.h +#include unistd.h +#include syslog.h +#include fcntl.h +#include sys/socket.h +#include netinet/in.h +#include netinet/ip.h +#include arpa/inet.h +#include string.h +#include linux/types.h +#include linux/if_addrlabel.h + +#include rt_names.h +#include utils.h +#include ip_common.h + +#define IFAL_RTA(r)((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg +#define IFAL_PAYLOAD(n)NLMSG_PAYLOAD(n,sizeof(struct ifaddrlblmsg)) + +extern struct rtnl_handle rth; + +static void usage(void) __attribute__((noreturn)); + +static void usage(void) +{ + fprintf(stderr, Usage: ip addrlabel [ list | add | del | flush ] prefix PREFIX [ dev DEV ] [ label LABEL ]\n); + exit(-1); +} + +int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +{ + FILE *fp = (FILE*)arg; + struct ifaddrlblmsg *ifal = NLMSG_DATA(n); + int len = n-nlmsg_len; + int host_len = -1; + struct rtattr *tb[IFAL_MAX+1]; + char abuf[256]; + + if (n-nlmsg_type != RTM_NEWADDRLABEL n-nlmsg_type != RTM_DELADDRLABEL) + return 0; + + len -= NLMSG_LENGTH(sizeof(*ifal)); + if (len 0) + return -1; + + parse_rtattr(tb, IFAL_MAX, IFAL_RTA(ifal), len); + + if (ifal-ifal_family == AF_INET) + host_len
Re: [PATCh TAKE 2] [IPROUTE2] Add addrlabel sub-command.
On Thu, 14 Feb 2008 03:20:12 +1100 (EST) YOSHIFUJI Hideaki / 吉藤英明 [EMAIL PROTECTED] wrote: Signed-off-by: YOSHIFUJI Hideaki [EMAIL PROTECTED] --- diff --git a/ip/Makefile b/ip/Makefile index b427d58..d908817 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -1,4 +1,4 @@ -IPOBJ=ip.o ipaddress.o iproute.o iprule.o \ +IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o \ rtm_map.o iptunnel.o ip6tunnel.o tunnel.o ipneigh.o ipntable.o iplink.o \ ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o \ ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o \ diff --git a/ip/ip.c b/ip/ip.c index aeb8c68..c4c773f 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -46,8 +46,8 @@ static void usage(void) fprintf(stderr, Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n ip [ -force ] [-batch filename\n -where OBJECT := { link | addr | route | rule | neigh | ntable | tunnel |\n - maddr | mroute | monitor | xfrm }\n +where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |\n + tunnel | maddr | mroute | monitor | xfrm }\n OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n -f[amily] { inet | inet6 | ipx | dnet | link } |\n -o[neline] | -t[imestamp] }\n); @@ -64,6 +64,7 @@ static const struct cmd { int (*func)(int argc, char **argv); } cmds[] = { { address,do_ipaddr }, + { addrlabel, do_ipaddrlabel }, { maddress, do_multiaddr }, { route, do_iproute }, { rule, do_iprule }, diff --git a/ip/ip_common.h b/ip/ip_common.h index 39f2507..1bbd50d 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -4,6 +4,9 @@ extern int print_linkinfo(const struct sockaddr_nl *who, extern int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); +extern int print_addrlabelinfo(const struct sockaddr_nl *who, +struct nlmsghdr *n, +void *arg); extern int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); extern int print_ntable(const struct sockaddr_nl *who, @@ -23,6 +26,7 @@ extern int print_prefix(const struct sockaddr_nl *who, extern int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); extern int do_ipaddr(int argc, char **argv); +extern int do_ipaddrlabel(int argc, char **argv); extern int do_iproute(int argc, char **argv); extern int do_iprule(int argc, char **argv); extern int do_ipneigh(int argc, char **argv); diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c new file mode 100644 index 000..1c873e9 --- /dev/null +++ b/ip/ipaddrlabel.c @@ -0,0 +1,260 @@ +/* + * ipaddrlabel.c ip addrlabel + * + * Copyright (C)2007 USAGI/WIDE Project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Based on iprule.c. + * + * Authors: YOSHIFUJI Hideaki [EMAIL PROTECTED] + * + */ + +#include stdio.h +#include stdlib.h +#include unistd.h +#include syslog.h +#include fcntl.h +#include sys/socket.h +#include netinet/in.h +#include netinet/ip.h +#include arpa/inet.h +#include string.h +#include linux/types.h +#include linux/if_addrlabel.h + +#include rt_names.h +#include utils.h +#include ip_common.h + +#define IFAL_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg +#define IFAL_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrlblmsg)) + +extern struct rtnl_handle rth; + +static void usage(void) __attribute__((noreturn)); + +static void usage(void) +{ + fprintf(stderr, Usage: ip addrlabel [ list | add | del | flush ] prefix PREFIX [ dev DEV ] [ label LABEL ]\n); + exit(-1); +} + +int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) +{ + FILE *fp = (FILE*)arg; + struct ifaddrlblmsg *ifal = NLMSG_DATA(n); + int len = n-nlmsg_len; + int host_len = -1; + struct rtattr *tb[IFAL_MAX+1]; + char abuf[256]; + + if (n-nlmsg_type != RTM_NEWADDRLABEL n-nlmsg_type != RTM_DELADDRLABEL) + return 0; + + len -=