]>
Commit | Line | Data |
---|---|---|
aba5acdf SH |
1 | #ifndef __UTILS_H__ |
2 | #define __UTILS_H__ 1 | |
3 | ||
5bd9dd49 | 4 | #include <sys/types.h> |
aba5acdf SH |
5 | #include <asm/types.h> |
6 | #include <resolv.h> | |
56b94061 | 7 | #include <stdlib.h> |
e998e118 | 8 | #include <stdbool.h> |
aba5acdf SH |
9 | |
10 | #include "libnetlink.h" | |
11 | #include "ll_map.h" | |
12 | #include "rtm_map.h" | |
13 | ||
14 | extern int preferred_family; | |
b68d9837 | 15 | extern int human_readable; |
1e264abc | 16 | extern int use_iec; |
aba5acdf SH |
17 | extern int show_stats; |
18 | extern int show_details; | |
19 | extern int show_raw; | |
20 | extern int resolve_hosts; | |
21 | extern int oneline; | |
90f93024 | 22 | extern int timestamp; |
79aa79d0 | 23 | extern int timestamp_short; |
aba5acdf | 24 | extern char * _SL_; |
64c79560 | 25 | extern int max_flush_loops; |
a3aa47a5 | 26 | extern int batch_mode; |
b13ba03f | 27 | extern bool do_all; |
aba5acdf SH |
28 | |
29 | #ifndef IPPROTO_ESP | |
30 | #define IPPROTO_ESP 50 | |
31 | #endif | |
32 | #ifndef IPPROTO_AH | |
33 | #define IPPROTO_AH 51 | |
34 | #endif | |
c7699875 | 35 | #ifndef IPPROTO_COMP |
36 | #define IPPROTO_COMP 108 | |
37 | #endif | |
bd641cd6 | 38 | #ifndef IPSEC_PROTO_ANY |
39 | #define IPSEC_PROTO_ANY 255 | |
40 | #endif | |
aba5acdf SH |
41 | |
42 | #define SPRINT_BSIZE 64 | |
43 | #define SPRINT_BUF(x) char x[SPRINT_BSIZE] | |
44 | ||
45 | extern void incomplete_command(void) __attribute__((noreturn)); | |
46 | ||
47 | #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0) | |
c7699875 | 48 | #define NEXT_ARG_OK() (argc - 1 > 0) |
49 | #define PREV_ARG() do { argv--; argc++; } while(0) | |
aba5acdf SH |
50 | |
51 | typedef struct | |
52 | { | |
53 | __u8 family; | |
54 | __u8 bytelen; | |
55 | __s16 bitlen; | |
f082b64f | 56 | __u32 flags; |
7f71c0ca | 57 | __u32 data[8]; |
aba5acdf SH |
58 | } inet_prefix; |
59 | ||
f082b64f | 60 | #define PREFIXLEN_SPECIFIED 1 |
61 | ||
aba5acdf SH |
62 | #define DN_MAXADDL 20 |
63 | #ifndef AF_DECnet | |
64 | #define AF_DECnet 12 | |
65 | #endif | |
66 | ||
ae665a52 | 67 | struct dn_naddr |
aba5acdf SH |
68 | { |
69 | unsigned short a_len; | |
70 | unsigned char a_addr[DN_MAXADDL]; | |
71 | }; | |
72 | ||
73 | #define IPX_NODE_LEN 6 | |
74 | ||
75 | struct ipx_addr { | |
76 | u_int32_t ipx_net; | |
77 | u_int8_t ipx_node[IPX_NODE_LEN]; | |
78 | }; | |
79 | ||
c7699875 | 80 | extern __u32 get_addr32(const char *name); |
04457b3d | 81 | extern int get_addr_1(inet_prefix *dst, const char *arg, int family); |
fb9b1d0f | 82 | extern int get_prefix_1(inet_prefix *dst, char *arg, int family); |
c7699875 | 83 | extern int get_addr(inet_prefix *dst, const char *arg, int family); |
fb9b1d0f | 84 | extern int get_prefix(inet_prefix *dst, char *arg, int family); |
6b1ac654 | 85 | extern int mask2bits(__u32 netmask); |
aba5acdf | 86 | |
04457b3d SH |
87 | extern int get_integer(int *val, const char *arg, int base); |
88 | extern int get_unsigned(unsigned *val, const char *arg, int base); | |
81d03dc3 | 89 | extern int get_time_rtt(unsigned *val, const char *arg, int *raw); |
aba5acdf SH |
90 | #define get_byte get_u8 |
91 | #define get_ushort get_u16 | |
92 | #define get_short get_s16 | |
c7699875 | 93 | extern int get_u64(__u64 *val, const char *arg, int base); |
04457b3d | 94 | extern int get_u32(__u32 *val, const char *arg, int base); |
30d10db5 | 95 | extern int get_s32(__s32 *val, const char *arg, int base); |
04457b3d SH |
96 | extern int get_u16(__u16 *val, const char *arg, int base); |
97 | extern int get_s16(__s16 *val, const char *arg, int base); | |
98 | extern int get_u8(__u8 *val, const char *arg, int base); | |
99 | extern int get_s8(__s8 *val, const char *arg, int base); | |
aba5acdf | 100 | |
f332d169 SH |
101 | extern char* hexstring_n2a(const __u8 *str, int len, char *buf, int blen); |
102 | extern __u8* hexstring_a2n(const char *str, __u8 *buf, int blen); | |
aba5acdf | 103 | |
ae665a52 | 104 | extern const char *format_host(int af, int len, const void *addr, |
04457b3d | 105 | char *buf, int buflen); |
656111b2 | 106 | extern const char *rt_addr_n2a(int af, const void *addr, |
04457b3d | 107 | char *buf, int buflen); |
aba5acdf | 108 | |
c7699875 | 109 | void missarg(const char *) __attribute__((noreturn)); |
04457b3d SH |
110 | void invarg(const char *, const char *) __attribute__((noreturn)); |
111 | void duparg(const char *, const char *) __attribute__((noreturn)); | |
112 | void duparg2(const char *, const char *) __attribute__((noreturn)); | |
113 | int matches(const char *arg, const char *pattern); | |
114 | extern int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits); | |
aba5acdf SH |
115 | |
116 | const char *dnet_ntop(int af, const void *addr, char *str, size_t len); | |
117 | int dnet_pton(int af, const char *src, void *addr); | |
118 | ||
119 | const char *ipx_ntop(int af, const void *addr, char *str, size_t len); | |
120 | int ipx_pton(int af, const char *src, void *addr); | |
121 | ||
122 | extern int __iproute2_hz_internal; | |
123 | extern int __get_hz(void); | |
124 | ||
125 | static __inline__ int get_hz(void) | |
126 | { | |
127 | if (__iproute2_hz_internal == 0) | |
128 | __iproute2_hz_internal = __get_hz(); | |
129 | return __iproute2_hz_internal; | |
130 | } | |
131 | ||
5e8bc631 | 132 | extern int __iproute2_user_hz_internal; |
133 | extern int __get_user_hz(void); | |
134 | ||
135 | static __inline__ int get_user_hz(void) | |
136 | { | |
137 | if (__iproute2_user_hz_internal == 0) | |
138 | __iproute2_user_hz_internal = __get_user_hz(); | |
139 | return __iproute2_user_hz_internal; | |
140 | } | |
141 | ||
8cd09e61 | 142 | static inline __u32 nl_mgrp(__u32 group) |
143 | { | |
56b94061 | 144 | if (group > 31 ) { |
145 | fprintf(stderr, "Use setsockopt for this group %d\n", group); | |
146 | exit(-1); | |
147 | } | |
148 | return group ? (1 << (group - 1)) : 0; | |
8cd09e61 | 149 | } |
150 | ||
151 | ||
90f93024 | 152 | int print_timestamp(FILE *fp); |
ddb1129b | 153 | void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n); |
90f93024 | 154 | |
02d2ae55 SH |
155 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
156 | ||
351efcde | 157 | extern int cmdlineno; |
d21e8835 | 158 | extern ssize_t getcmdline(char **line, size_t *len, FILE *in); |
351efcde | 159 | extern int makeargs(char *line, char *argv[], int maxargs); |
aa574cd6 | 160 | extern int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6); |
351efcde | 161 | |
909dfe2c PE |
162 | struct iplink_req; |
163 | int iplink_parse(int argc, char **argv, struct iplink_req *req, | |
db02608b | 164 | char **name, char **type, char **link, char **dev, |
5e25cf77 | 165 | int *group, int *index); |
ddb1129b | 166 | |
e998e118 VK |
167 | extern int do_each_netns(int (*func)(char *nsname, void *arg), void *arg, |
168 | bool show_label); | |
169 | ||
aba5acdf | 170 | #endif /* __UTILS_H__ */ |