1 /* vi: set sw=4 ts=4: */
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
15 const char* FAST_FUNC
rtnl_rtntype_n2a(int id
, char *buf
)
43 /* buf is SPRINT_BSIZE big */
44 sprintf(buf
, "%d", id
);
50 int FAST_FUNC
rtnl_rtntype_a2n(int *id
, char *arg
)
52 static const char keywords
[] ALIGN1
=
53 "local\0""nat\0""broadcast\0""brd\0""anycast\0"
54 "multicast\0""prohibit\0""unreachable\0""blackhole\0"
55 "xresolve\0""unicast\0""throw\0";
57 ARG_local
= 1, ARG_nat
, ARG_broadcast
, ARG_brd
, ARG_anycast
,
58 ARG_multicast
, ARG_prohibit
, ARG_unreachable
, ARG_blackhole
,
59 ARG_xresolve
, ARG_unicast
, ARG_throw
61 const smalluint key
= index_in_substrings(keywords
, arg
) + 1;
67 else if (key
== ARG_nat
)
69 else if (key
== ARG_broadcast
|| key
== ARG_brd
)
71 else if (key
== ARG_anycast
)
73 else if (key
== ARG_multicast
)
75 else if (key
== ARG_prohibit
)
77 else if (key
== ARG_unreachable
)
78 res
= RTN_UNREACHABLE
;
79 else if (key
== ARG_blackhole
)
81 else if (key
== ARG_xresolve
)
83 else if (key
== ARG_unicast
)
85 else if (key
== ARG_throw
)
88 res
= strtoul(arg
, &end
, 0);
89 if (end
== arg
|| *end
|| res
> 255)
96 int FAST_FUNC
get_rt_realms(uint32_t *realms
, char *arg
)
99 char *p
= strchr(arg
, '/');
104 if (rtnl_rtrealm_a2n(realms
, arg
)) {
112 if (*arg
&& rtnl_rtrealm_a2n(&realm
, arg
))