10 #include "libnetlink.h"
14 extern int preferred_family
;
15 extern int human_readable
;
17 extern int show_stats
;
18 extern int show_details
;
20 extern int resolve_hosts
;
24 extern int timestamp_short
;
25 extern const char * _SL_
;
26 extern int max_flush_loops
;
27 extern int batch_mode
;
31 #define IPPROTO_ESP 50
37 #define IPPROTO_COMP 108
39 #ifndef IPSEC_PROTO_ANY
40 #define IPSEC_PROTO_ANY 255
44 #define CONFDIR "/etc/iproute2"
47 #define SPRINT_BSIZE 64
48 #define SPRINT_BUF(x) char x[SPRINT_BSIZE]
50 void incomplete_command(void) __attribute__((noreturn
));
52 #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0)
53 #define NEXT_ARG_OK() (argc - 1 > 0)
54 #define NEXT_ARG_FWD() do { argv++; argc--; } while(0)
55 #define PREV_ARG() do { argv--; argc++; } while(0)
62 /* These next two fields match rtvia */
67 #define PREFIXLEN_SPECIFIED 1
77 unsigned char a_addr
[DN_MAXADDL
];
80 #define IPX_NODE_LEN 6
84 u_int8_t ipx_node
[IPX_NODE_LEN
];
91 /* Maximum number of labels the mpls helpers support */
92 #define MPLS_MAX_LABELS 8
94 __u32
get_addr32(const char *name
);
95 int get_addr_1(inet_prefix
*dst
, const char *arg
, int family
);
96 int get_prefix_1(inet_prefix
*dst
, char *arg
, int family
);
97 int get_addr(inet_prefix
*dst
, const char *arg
, int family
);
98 int get_prefix(inet_prefix
*dst
, char *arg
, int family
);
99 int mask2bits(__u32 netmask
);
101 int get_integer(int *val
, const char *arg
, int base
);
102 int get_unsigned(unsigned *val
, const char *arg
, int base
);
103 int get_time_rtt(unsigned *val
, const char *arg
, int *raw
);
104 #define get_byte get_u8
105 #define get_ushort get_u16
106 #define get_short get_s16
107 int get_u64(__u64
*val
, const char *arg
, int base
);
108 int get_u32(__u32
*val
, const char *arg
, int base
);
109 int get_s32(__s32
*val
, const char *arg
, int base
);
110 int get_u16(__u16
*val
, const char *arg
, int base
);
111 int get_s16(__s16
*val
, const char *arg
, int base
);
112 int get_u8(__u8
*val
, const char *arg
, int base
);
113 int get_s8(__s8
*val
, const char *arg
, int base
);
115 char* hexstring_n2a(const __u8
*str
, int len
, char *buf
, int blen
);
116 __u8
* hexstring_a2n(const char *str
, __u8
*buf
, int blen
);
118 int af_bit_len(int af
);
119 int af_byte_len(int af
);
121 const char *format_host(int af
, int len
, const void *addr
,
122 char *buf
, int buflen
);
123 const char *rt_addr_n2a(int af
, int len
, const void *addr
,
124 char *buf
, int buflen
);
126 int read_family(const char *name
);
127 const char *family_name(int family
);
129 void missarg(const char *) __attribute__((noreturn
));
130 void invarg(const char *, const char *) __attribute__((noreturn
));
131 void duparg(const char *, const char *) __attribute__((noreturn
));
132 void duparg2(const char *, const char *) __attribute__((noreturn
));
133 int matches(const char *arg
, const char *pattern
);
134 int inet_addr_match(const inet_prefix
*a
, const inet_prefix
*b
, int bits
);
136 const char *dnet_ntop(int af
, const void *addr
, char *str
, size_t len
);
137 int dnet_pton(int af
, const char *src
, void *addr
);
139 const char *ipx_ntop(int af
, const void *addr
, char *str
, size_t len
);
140 int ipx_pton(int af
, const char *src
, void *addr
);
142 const char *mpls_ntop(int af
, const void *addr
, char *str
, size_t len
);
143 int mpls_pton(int af
, const char *src
, void *addr
);
145 extern int __iproute2_hz_internal
;
148 static __inline__
int get_hz(void)
150 if (__iproute2_hz_internal
== 0)
151 __iproute2_hz_internal
= __get_hz();
152 return __iproute2_hz_internal
;
155 extern int __iproute2_user_hz_internal
;
156 int __get_user_hz(void);
158 static __inline__
int get_user_hz(void)
160 if (__iproute2_user_hz_internal
== 0)
161 __iproute2_user_hz_internal
= __get_user_hz();
162 return __iproute2_user_hz_internal
;
165 static inline __u32
nl_mgrp(__u32 group
)
168 fprintf(stderr
, "Use setsockopt for this group %d\n", group
);
171 return group
? (1 << (group
- 1)) : 0;
175 int print_timestamp(FILE *fp
);
176 void print_nlmsg_timestamp(FILE *fp
, const struct nlmsghdr
*n
);
178 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
180 #define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
183 # define offsetof(type, member) ((size_t) &((type *)0)->member)
187 # define min(x, y) ({ \
188 typeof(x) _min1 = (x); \
189 typeof(y) _min2 = (y); \
190 (void) (&_min1 == &_min2); \
191 _min1 < _min2 ? _min1 : _min2; })
194 #ifndef __check_format_string
195 # define __check_format_string(pos_str, pos_args) \
196 __attribute__ ((format (printf, (pos_str), (pos_args))))
199 #define _textify(x) #x
200 #define textify(x) _textify(x)
202 #define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
203 #define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
205 extern int cmdlineno
;
206 ssize_t
getcmdline(char **line
, size_t *len
, FILE *in
);
207 int makeargs(char *line
, char *argv
[], int maxargs
);
208 int inet_get_addr(const char *src
, __u32
*dst
, struct in6_addr
*dst6
);
211 int iplink_parse(int argc
, char **argv
, struct iplink_req
*req
,
212 char **name
, char **type
, char **link
, char **dev
,
213 int *group
, int *index
);
215 int do_each_netns(int (*func
)(char *nsname
, void *arg
), void *arg
,
218 char *int_to_str(int val
, char *buf
);
220 #endif /* __UTILS_H__ */