Import patch ipxfrm-20040707_2.diff

(Logical change 1.53)
parent 7798b523
......@@ -15,6 +15,7 @@ struct rtnl_handle
};
extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions);
extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol);
extern void rtnl_close(struct rtnl_handle *rth);
extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type);
extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len);
......@@ -36,6 +37,7 @@ extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data);
extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen);
extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);
extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len);
extern int rtnl_listen(struct rtnl_handle *, int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
void *jarg);
......
......@@ -22,6 +22,9 @@ extern char * _SL_;
#ifndef IPPROTO_AH
#define IPPROTO_AH 51
#endif
#ifndef IPPROTO_COMP
#define IPPROTO_COMP 108
#endif
#define SPRINT_BSIZE 64
#define SPRINT_BUF(x) char x[SPRINT_BSIZE]
......@@ -29,6 +32,8 @@ extern char * _SL_;
extern void incomplete_command(void) __attribute__((noreturn));
#define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
#define NEXT_ARG_OK() (argc - 1 > 0)
#define PREV_ARG() do { argv--; argc++; } while(0)
typedef struct
{
......@@ -56,17 +61,18 @@ struct ipx_addr {
u_int8_t ipx_node[IPX_NODE_LEN];
};
extern __u32 get_addr32(char *name);
extern __u32 get_addr32(const char *name);
extern int get_addr_1(inet_prefix *dst, const char *arg, int family);
extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
extern int get_addr(inet_prefix *dst, char *arg, int family);
extern int get_prefix(inet_prefix *dst, char *arg, int family);
extern int get_prefix_1(inet_prefix *dst, const char *arg, int family);
extern int get_addr(inet_prefix *dst, const char *arg, int family);
extern int get_prefix(inet_prefix *dst, const char *arg, int family);
extern int get_integer(int *val, const char *arg, int base);
extern int get_unsigned(unsigned *val, const char *arg, int base);
#define get_byte get_u8
#define get_ushort get_u16
#define get_short get_s16
extern int get_u64(__u64 *val, const char *arg, int base);
extern int get_u32(__u32 *val, const char *arg, int base);
extern int get_u16(__u16 *val, const char *arg, int base);
extern int get_s16(__s16 *val, const char *arg, int base);
......@@ -81,6 +87,7 @@ extern const char *format_host(int af, int len, const void *addr,
extern const char *rt_addr_n2a(int af, int len, const void *addr,
char *buf, int buflen);
void missarg(const char *) __attribute__((noreturn));
void invarg(const char *, const char *) __attribute__((noreturn));
void duparg(const char *, const char *) __attribute__((noreturn));
void duparg2(const char *, const char *) __attribute__((noreturn));
......
IPOBJ=ip.o ipaddress.o iproute.o iprule.o \
rtm_map.o iptunnel.o ipneigh.o iplink.o ipmaddr.o \
ipmonitor.o ipmroute.o
ipmonitor.o ipmroute.o ipxfrm.o xfrm_state.o xfrm_policy.o
RTMONOBJ=rtmon.o
......
......@@ -40,7 +40,7 @@ static void usage(void)
fprintf(stderr,
"Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n"
"where OBJECT := { link | addr | route | rule | neigh | tunnel |\n"
" maddr | mroute | monitor }\n"
" maddr | mroute | monitor | xfrm }\n"
" OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] |\n"
" -f[amily] { inet | inet6 | ipx | dnet | link } | -o[neline] }\n");
exit(-1);
......@@ -136,6 +136,8 @@ int main(int argc, char **argv)
return do_iptunnel(argc-1, argv+1);
if (strcmp(basename, "ipmonitor") == 0)
return do_ipmonitor(argc-1, argv+1);
if (strcmp(basename, "ipxfrm") == 0)
return do_xfrm(argc-1, argv+1);
if (argc > 1) {
if (matches(argv[1], "address") == 0)
......@@ -158,6 +160,8 @@ int main(int argc, char **argv)
return do_iptunnel(argc-2, argv+2);
if (matches(argv[1], "monitor") == 0)
return do_ipmonitor(argc-2, argv+2);
if (matches(argv[1], "xfrm") == 0)
return do_xfrm(argc-2, argv+2);
if (matches(argv[1], "help") == 0)
usage();
fprintf(stderr, "Object \"%s\" is unknown, try \"ip help\".\n", argv[1]);
......
......@@ -18,3 +18,4 @@ extern int do_iplink(int argc, char **argv);
extern int do_ipmonitor(int argc, char **argv);
extern int do_multiaddr(int argc, char **argv);
extern int do_multiroute(int argc, char **argv);
extern int do_xfrm(int argc, char **argv);
This diff is collapsed.
/* $USAGI: $ */
/*
* Copyright (C)2004 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
*/
/*
* Authors:
* Masahide NAKAMURA @USAGI
*/
#ifndef __XFRM_H__
#define __XFRM_H__ 1
#include <stdio.h>
#include <sys/socket.h>
#include <linux/xfrm.h>
#include "utils.h"
#define XFRM_MAX_DEPTH 6
#define XFRMS_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info))))
#define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info))
#define XFRMP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info))))
#define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info))
struct xfrm_buffer {
char *buf;
int size;
int offset;
int nlmsg_count;
struct rtnl_handle *rth;
};
struct xfrm_filter {
int use;
struct xfrm_usersa_info xsinfo;
__u32 id_src_mask;
__u32 id_dst_mask;
__u32 id_proto_mask;
__u32 id_spi_mask;
__u32 mode_mask;
__u32 reqid_mask;
__u32 state_flags_mask;
struct xfrm_userpolicy_info xpinfo;
__u32 dir_mask;
__u32 sel_src_mask;
__u32 sel_dst_mask;
__u32 sel_dev_mask;
__u32 upspec_proto_mask;
__u32 upspec_sport_mask;
__u32 upspec_dport_mask;
__u32 index_mask;
__u32 action_mask;
__u32 priority_mask;
};
#define XFRM_FILTER_MASK_FULL (~(__u32)0)
extern struct xfrm_filter filter;
int do_xfrm_state(int argc, char **argv);
int do_xfrm_policy(int argc, char **argv);
const char *strxf_flags(__u8 flags);
const char *strxf_share(__u8 share);
void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
__u8 mode, __u32 reqid, __u16 family, FILE *fp,
const char *prefix);
void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix);
void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
struct xfrm_lifetime_cur *cur,
FILE *fp, const char *prefix);
void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
FILE *fp, const char *prefix);
void xfrm_xfrma_print(struct rtattr *tb[], int ntb, __u16 family,
FILE *fp, const char *prefix);
int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
int *argcp, char ***argvp);
int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp);
int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp);
int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp);
int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft,
int *argcp, char ***argvp);
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -30,13 +30,13 @@ void rtnl_close(struct rtnl_handle *rth)
close(rth->fd);
}
int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol)
{
int addr_len;
memset(rth, 0, sizeof(rth));
rth->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
rth->fd = socket(AF_NETLINK, SOCK_RAW, protocol);
if (rth->fd < 0) {
perror("Cannot open netlink socket");
return -1;
......@@ -67,6 +67,11 @@ int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
return 0;
}
int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
{
return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE);
}
int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
{
struct {
......@@ -521,3 +526,16 @@ int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
return 0;
}
int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len)
{
int i = 0;
while (RTA_OK(rta, len)) {
if (rta->rta_type <= max)
tb[i++] = rta;
rta = RTA_NEXT(rta,len);
}
if (len)
fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
return i;
}
......@@ -58,6 +58,20 @@ int get_unsigned(unsigned *val, const char *arg, int base)
return 0;
}
int get_u64(__u64 *val, const char *arg, int base)
{
unsigned long long res;
char *ptr;
if (!arg || !*arg)
return -1;
res = strtoull(arg, &ptr, base);
if (!ptr || ptr == arg || *ptr || res == 0xFFFFFFFFULL)
return -1;
*val = res;
return 0;
}
int get_u32(__u32 *val, const char *arg, int base)
{
unsigned long res;
......@@ -186,7 +200,7 @@ int get_addr_1(inet_prefix *addr, const char *name, int family)
return 0;
}
int get_prefix_1(inet_prefix *dst, char *arg, int family)
int get_prefix_1(inet_prefix *dst, const char *arg, int family)
{
int err;
unsigned plen;
......@@ -235,7 +249,7 @@ done:
return err;
}
int get_addr(inet_prefix *dst, char *arg, int family)
int get_addr(inet_prefix *dst, const char *arg, int family)
{
if (family == AF_PACKET) {
fprintf(stderr, "Error: \"%s\" may be inet address, but it is not allowed in this context.\n", arg);
......@@ -248,7 +262,7 @@ int get_addr(inet_prefix *dst, char *arg, int family)
return 0;
}
int get_prefix(inet_prefix *dst, char *arg, int family)
int get_prefix(inet_prefix *dst, const char *arg, int family)
{
if (family == AF_PACKET) {
fprintf(stderr, "Error: \"%s\" may be inet prefix, but it is not allowed in this context.\n", arg);
......@@ -261,7 +275,7 @@ int get_prefix(inet_prefix *dst, char *arg, int family)
return 0;
}
__u32 get_addr32(char *name)
__u32 get_addr32(const char *name)
{
inet_prefix addr;
if (get_addr_1(&addr, name, AF_INET)) {
......@@ -277,6 +291,12 @@ void incomplete_command(void)
exit(-1);
}
void missarg(const char *key)
{
fprintf(stderr, "Error: argument \"%s\" is required\n", key);
exit(-1);
}
void invarg(const char *msg, const char *arg)
{
fprintf(stderr, "Error: argument \"%s\" is wrong: %s\n", arg, msg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment