use RT_ROUNDUP provided by net/route.h

This commit is contained in:
kefren 2011-02-09 11:38:57 +00:00
parent a804f47907
commit 34493327dd
2 changed files with 8 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mpls_interface.c,v 1.4 2011/01/04 10:18:42 kefren Exp $ */ /* $NetBSD: mpls_interface.c,v 1.5 2011/02/09 11:38:57 kefren Exp $ */
/*- /*-
* Copyright (c) 2010 The NetBSD Foundation, Inc. * Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -32,6 +32,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netmpls/mpls.h> #include <netmpls/mpls.h>
#include <net/route.h>
#include <sys/param.h> #include <sys/param.h>
@ -49,9 +50,6 @@
#include "mpls_interface.h" #include "mpls_interface.h"
#include "mpls_routes.h" #include "mpls_routes.h"
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
int int
mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg, mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg,
struct in_addr * addr, int len, int label, int rlookup) struct in_addr * addr, int len, int label, int rlookup)
@ -116,7 +114,7 @@ mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg,
so_gate = (union sockunion *) rgp->m_space; so_gate = (union sockunion *) rgp->m_space;
so_gate = (union sockunion *)((char*)so_gate + so_gate = (union sockunion *)((char*)so_gate +
ROUNDUP(so_gate->sa.sa_len)); RT_ROUNDUP(so_gate->sa.sa_len));
if (rgp->m_rtm.rtm_addrs & RTA_IFA) { if (rgp->m_rtm.rtm_addrs & RTA_IFA) {
int li = 1; int li = 1;
so_oldifa = so_gate; so_oldifa = so_gate;
@ -128,7 +126,7 @@ mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg,
li++; li++;
for (int i = 0; i < li; i++) for (int i = 0; i < li; i++)
so_oldifa = (union sockunion *)((char*)so_oldifa + so_oldifa = (union sockunion *)((char*)so_oldifa +
ROUNDUP(so_oldifa->sa.sa_len)); RT_ROUNDUP(so_oldifa->sa.sa_len));
} }
if (so_gate->sa.sa_family != AF_INET) { if (so_gate->sa.sa_family != AF_INET) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: mpls_routes.c,v 1.3 2011/01/04 10:58:15 kefren Exp $ */ /* $NetBSD: mpls_routes.c,v 1.4 2011/02/09 11:38:57 kefren Exp $ */
/*- /*-
* Copyright (c) 2010 The NetBSD Foundation, Inc. * Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -71,14 +71,12 @@ extern struct sockaddr mplssockaddr;
/* Many lines inspired or shamelessly stolen from sbin/route/route.c */ /* Many lines inspired or shamelessly stolen from sbin/route/route.c */
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define NEXTADDR(u) \ #define NEXTADDR(u) \
do { l = ROUNDUP(u->sa.sa_len); memcpy(cp, u, l); cp += l; } while(0); do { l = RT_ROUNDUP(u->sa.sa_len); memcpy(cp, u, l); cp += l; } while(0);
#define NEXTADDR2(u) \ #define NEXTADDR2(u) \
do { l = ROUNDUP(u.sa_len); memcpy(cp, &u, l); cp += l; } while(0); do { l = RT_ROUNDUP(u.sa_len); memcpy(cp, &u, l); cp += l; } while(0);
#define GETNEXT(sunion) \ #define GETNEXT(sunion) \
(union sockunion *) ((char *) (sunion) + ROUNDUP((sunion)->sa.sa_len)) (union sockunion *) ((char *) (sunion) + RT_ROUNDUP((sunion)->sa.sa_len))
int int
read_route_socket(char *s, int max) read_route_socket(char *s, int max)