mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-21 09:11:54 +00:00
Integrated address print lengths
Minor changes by Ondrej Santiago Zajicek
This commit is contained in:
parent
9656dce72e
commit
7fd4143ead
10
lib/ip.h
10
lib/ip.h
@ -33,6 +33,10 @@
|
||||
#define IP4_MAX_PREFIX_LENGTH 32
|
||||
#define IP6_MAX_PREFIX_LENGTH 128
|
||||
|
||||
#define IP4_MAX_TEXT_LENGTH 15 /* "255.255.255.255" */
|
||||
#define IP6_MAX_TEXT_LENGTH 39 /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" */
|
||||
#define IPA_MAX_TEXT_LENGTH 39
|
||||
|
||||
#define IP4_MIN_MTU 576
|
||||
#define IP6_MIN_MTU 1280
|
||||
|
||||
@ -42,12 +46,6 @@
|
||||
#define IP6_HEADER_LENGTH 40
|
||||
#define UDP_HEADER_LENGTH 8
|
||||
|
||||
#ifdef IPV6
|
||||
#define STD_ADDRESS_P_LENGTH 39
|
||||
#else
|
||||
#define STD_ADDRESS_P_LENGTH 15
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUGGING
|
||||
|
||||
|
@ -18,6 +18,13 @@ const u8 net_max_prefix_length[] = {
|
||||
[NET_VPN6] = IP4_MAX_PREFIX_LENGTH
|
||||
};
|
||||
|
||||
const u16 net_max_text_length[] = {
|
||||
[NET_IP4] = 18, /* "255.255.255.255/32" */
|
||||
[NET_IP6] = 43, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
|
||||
[NET_VPN4] = 40, /* "4294967296:4294967296 255.255.255.255/32" */
|
||||
[NET_VPN6] = 65, /* "4294967296:4294967296 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
net_format(const net_addr *N, char *buf, int buflen)
|
||||
|
10
lib/net.h
10
lib/net.h
@ -68,7 +68,11 @@ typedef union net_addr_union {
|
||||
|
||||
|
||||
extern const u16 net_addr_length[];
|
||||
extern const u8 net_max_prefix_length[];
|
||||
extern const u8 net_max_prefix_length[];
|
||||
extern const u16 net_max_text_length[];
|
||||
|
||||
#define NET_MAX_TEXT_LENGTH 65
|
||||
|
||||
|
||||
#define NET_ADDR_IP4(prefix,pxlen) \
|
||||
((net_addr_ip4) { NET_IP4, pxlen, sizeof(net_addr_ip4), prefix })
|
||||
@ -103,6 +107,7 @@ static inline void net_fill_ipa(net_addr *a, ip_addr prefix, uint pxlen)
|
||||
net_fill_ip6(a, ipa_to_ip6(prefix), pxlen);
|
||||
}
|
||||
|
||||
|
||||
static inline ip4_addr net4_prefix(const net_addr *a)
|
||||
{ return ((net_addr_ip4 *) a)->prefix; }
|
||||
|
||||
@ -243,6 +248,3 @@ int net_in_netX(const net_addr *A, const net_addr *N);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
23
lib/printf.c
23
lib/printf.c
@ -139,7 +139,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
u32 x;
|
||||
char *str, *start;
|
||||
const char *s;
|
||||
char ipbuf[STD_ADDRESS_P_LENGTH+1];
|
||||
char ipbuf[NET_MAX_TEXT_LENGTH+1];
|
||||
struct iface *iface;
|
||||
|
||||
int flags; /* flags to number() */
|
||||
@ -156,7 +156,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
*str++ = *fmt;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/* process flags */
|
||||
flags = 0;
|
||||
repeat:
|
||||
@ -236,12 +236,14 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
case 'M':
|
||||
s = strerror(va_arg(args, int));
|
||||
goto str;
|
||||
case 'N':
|
||||
case 'N': {
|
||||
net_addr *n = va_arg(args, net_addr *);
|
||||
if (field_width == 1)
|
||||
field_width = STD_ADDRESS_P_LENGTH; /* XXXX */
|
||||
net_format(va_arg(args, net_addr *), ipbuf, sizeof(ipbuf));
|
||||
field_width = net_max_text_length[n->type];
|
||||
net_format(n, ipbuf, sizeof(ipbuf));
|
||||
s = ipbuf;
|
||||
goto str;
|
||||
}
|
||||
case 's':
|
||||
s = va_arg(args, char *);
|
||||
if (!s)
|
||||
@ -287,17 +289,18 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
continue;
|
||||
|
||||
/* IP address */
|
||||
case 'I':
|
||||
case 'I': {
|
||||
ip_addr a = va_arg(args, ip_addr);
|
||||
if (flags & SPECIAL)
|
||||
ipa_ntox(va_arg(args, ip_addr), ipbuf);
|
||||
ipa_ntox(a, ipbuf);
|
||||
else {
|
||||
ipa_ntop(va_arg(args, ip_addr), ipbuf);
|
||||
ipa_ntop(a, ipbuf);
|
||||
if (field_width == 1)
|
||||
field_width = STD_ADDRESS_P_LENGTH;
|
||||
field_width = (ipa_is_ip4(a) ? IP4_MAX_TEXT_LENGTH : IP6_MAX_TEXT_LENGTH);
|
||||
}
|
||||
s = ipbuf;
|
||||
goto str;
|
||||
|
||||
}
|
||||
/* Interface scope after link-local IP address */
|
||||
case 'J':
|
||||
iface = va_arg(args, struct iface *);
|
||||
|
@ -742,7 +742,7 @@ iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct ifac
|
||||
static void
|
||||
if_show_addr(struct ifa *a)
|
||||
{
|
||||
byte opp[STD_ADDRESS_P_LENGTH + 16];
|
||||
byte opp[IPA_MAX_TEXT_LENGTH + 16];
|
||||
|
||||
if (ipa_nonzero(a->opposite))
|
||||
bsprintf(opp, ", opposite %I", a->opposite);
|
||||
@ -793,7 +793,7 @@ void
|
||||
if_show_summary(void)
|
||||
{
|
||||
struct iface *i;
|
||||
byte addr[STD_ADDRESS_P_LENGTH + 16];
|
||||
byte addr[IPA_MAX_TEXT_LENGTH + 16];
|
||||
|
||||
cli_msg(-2005, "interface state address");
|
||||
WALK_LIST(i, iface_list)
|
||||
|
@ -220,7 +220,7 @@ rte_mergable(rte *pri, rte *sec)
|
||||
static void
|
||||
rte_trace(struct proto *p, rte *e, int dir, char *msg)
|
||||
{
|
||||
byte via[STD_ADDRESS_P_LENGTH+32];
|
||||
byte via[IPA_MAX_TEXT_LENGTH+32];
|
||||
|
||||
rt_format_via(e, via);
|
||||
log(L_TRACE "%s %c %s %N %s", p->name, dir, msg, e->net->n.addr, via);
|
||||
@ -2383,7 +2383,8 @@ rt_format_via(rte *e, byte *via)
|
||||
static void
|
||||
rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, ea_list *tmpa)
|
||||
{
|
||||
byte via[STD_ADDRESS_P_LENGTH+32], from[STD_ADDRESS_P_LENGTH+8];
|
||||
byte via[IPA_MAX_TEXT_LENGTH+32];
|
||||
byte from[IPA_MAX_TEXT_LENGTH+8];
|
||||
byte tm[TM_DATETIME_BUFFER_SIZE], info[256];
|
||||
rta *a = e->attrs;
|
||||
int primary = (e->net->routes == e);
|
||||
@ -2424,7 +2425,7 @@ static void
|
||||
rt_show_net(struct cli *c, net *n, struct rt_show_data *d)
|
||||
{
|
||||
rte *e, *ee;
|
||||
byte ia[STD_ADDRESS_P_LENGTH+8];
|
||||
byte ia[NET_MAX_TEXT_LENGTH+1];
|
||||
struct ea_list *tmpa;
|
||||
struct announce_hook *a = NULL;
|
||||
int first = 1;
|
||||
|
@ -1094,7 +1094,7 @@ static inline void
|
||||
show_lsa_external(struct top_hash_entry *he, int ospf2)
|
||||
{
|
||||
struct ospf_lsa_ext_local rt;
|
||||
char str_via[STD_ADDRESS_P_LENGTH + 8] = "";
|
||||
char str_via[IPA_MAX_TEXT_LENGTH + 8] = "";
|
||||
char str_tag[16] = "";
|
||||
|
||||
if (he->lsa_type == LSA_T_EXT)
|
||||
|
@ -643,7 +643,7 @@ struct protocol proto_static = {
|
||||
static void
|
||||
static_show_rt(struct static_route *r)
|
||||
{
|
||||
byte via[STD_ADDRESS_P_LENGTH + 16];
|
||||
byte via[IPA_MAX_TEXT_LENGTH + 25];
|
||||
|
||||
switch (r->dest)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user