Skip to content

Commit

Permalink
MIP6: compile on NetBSD, RR work without RR_DEBUG and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
k-sugyou committed Jul 24, 2002
1 parent 3c1b3af commit e4af002
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
15 changes: 10 additions & 5 deletions kame/sys/netinet6/mip6.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: mip6.c,v 1.145 2002/07/23 13:23:23 t-momose Exp $ */
/* $KAME: mip6.c,v 1.146 2002/07/24 08:53:36 k-sugyou Exp $ */

/*
* Copyright (C) 2001 WIDE Project. All rights reserved.
Expand Down Expand Up @@ -199,7 +199,9 @@ static int mip6_haddr_destopt_create __P((struct ip6_dest **,
#ifdef MIP6_DRAFT17
static void mip6_create_nonce __P((mip6_nonce_t *));
static void mip6_create_nodekey __P((mip6_nodekey_t *));
#if 0
static void mip6_update_nonce_nodekey(void);
#endif
#endif /* MIP6_DRAFT17 */

#if defined(IPSEC) && !defined(__OpenBSD__)
Expand Down Expand Up @@ -2536,6 +2538,7 @@ mip6_create_nodekey(nodekey)
((u_long *)nodekey)[i] = random();
}

#if 0
/* This function should be called periodically */
static void
mip6_update_nonce_nodekey()
Expand All @@ -2547,6 +2550,7 @@ mip6_update_nonce_nodekey()
mip6_create_nonce(nonce_head);
mip6_create_nodekey(mip6_nodekey + (nonce_head - mip6_nonce));
}
#endif

int
mip6_get_nonce(index, nonce)
Expand Down Expand Up @@ -2650,22 +2654,22 @@ printf("CN: Careof Nodekey: %*D\n", sizeof(coa_nodekey), &coa_nodekey, ":");

/* Calculate home cookie */
mip6_create_cookie(&ip6mu->ip6mu_addr,
&home_nodekey, &home_nonce, &home_cookie);
&home_nodekey, &home_nonce, home_cookie);
#if RR_DBG
printf("CN: Home Cookie: %*D\n", sizeof(home_cookie), (u_int8_t *)&home_cookie, ":");
#endif

/* Calculate care-of cookie */
mip6_create_cookie(&ip6->ip6_src,
&coa_nodekey, &careof_nonce, &careof_cookie);
&coa_nodekey, &careof_nonce, careof_cookie);
#if RR_DBG
printf("CN: Care-of Cookie: %*D\n", sizeof(careof_cookie), (u_int8_t *)&careof_cookie, ":");
#endif

/* Calculate K_bu */
SHA1Init(&sha1_ctx);
SHA1Update(&sha1_ctx, (caddr_t)&home_cookie, sizeof(home_cookie));
SHA1Update(&sha1_ctx, (caddr_t)&careof_cookie, sizeof(careof_cookie));
SHA1Update(&sha1_ctx, (caddr_t)home_cookie, sizeof(home_cookie));
SHA1Update(&sha1_ctx, (caddr_t)careof_cookie, sizeof(careof_cookie));
SHA1Final(key_bu, &sha1_ctx);
#if RR_DBG
printf("CN: K_bu: %*D\n", sizeof(key_bu), key_bu, ":");
Expand Down Expand Up @@ -2699,6 +2703,7 @@ printf("CN: Auth: %*D\n", (u_int8_t *)mopt->mopt_auth - (u_int8_t *)ip6mu, ip6mu
printf("CN: Auth: %*D\n", restlen, mopt->mopt_auth + ((struct ip6m_opt_authdata *)mopt->mopt_auth)->ip6moau_len, ":");
#endif
}
bzero(authdata, sizeof(authdata));
hmac_result(&hmac_ctx, authdata);
#if RR_DBG
printf("CN: Auth Data: %*D\n", sizeof(authdata), authdata, ":");
Expand Down
12 changes: 10 additions & 2 deletions kame/sys/netinet6/mip6_binding.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: mip6_binding.c,v 1.109 2002/06/26 02:33:36 k-sugyou Exp $ */
/* $KAME: mip6_binding.c,v 1.110 2002/07/24 08:53:36 k-sugyou Exp $ */

/*
* Copyright (C) 2001 WIDE Project. All rights reserved.
Expand Down Expand Up @@ -494,6 +494,9 @@ mip6_bu_list_notify_binding_change(sc)
} else {
mbu->mbu_lifetime = mpfx->mpfx_pltime;
}
if (mip6_config.mcfg_bu_maxlifetime > 0 &&
mbu->mbu_lifetime > mip6_config.mcfg_bu_maxlifetime)
mbu->mbu_lifetime = mip6_config.mcfg_bu_maxlifetime;
mbu->mbu_expire = time_second + mbu->mbu_lifetime;
/* sanity check for overflow */
if (mbu->mbu_expire < time_second)
Expand Down Expand Up @@ -2611,7 +2614,6 @@ mip6_route_optimize(m)
struct mip6_prefix *mpfx;
struct mip6_bu *mbu;
struct hif_softc *sc;
int32_t coa_lifetime;
int error = 0;

if (!MIP6_IS_MN) {
Expand Down Expand Up @@ -2696,6 +2698,8 @@ mip6_route_optimize(m)
}
mip6_bu_list_insert(&sc->hif_bu_list, mbu);
} else {
#if 0
int32_t coa_lifetime;
#if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
long time_second = time.tv_sec;
#endif
Expand All @@ -2711,6 +2715,9 @@ mip6_route_optimize(m)
} else {
mbu->mbu_lifetime = mpfx->mpfx_pltime;
}
if (mip6_config.mcfg_bu_maxlifetime > 0 &&
mbu->mbu_lifetime > mip6_config.mcfg_bu_maxlifetime)
mbu->mbu_lifetime = mip6_config.mcfg_bu_maxlifetime;
mbu->mbu_expire = time_second + mbu->mbu_lifetime;
/* sanity check for overflow */
if (mbu->mbu_expire < time_second)
Expand All @@ -2720,6 +2727,7 @@ mip6_route_optimize(m)
/* sanity check for overflow */
if (mbu->mbu_refexpire < time_second)
mbu->mbu_refexpire = 0x7fffffff;
#endif
}
mip6_bu_fsm(mbu, MIP6_BU_FSM_EVENT_RO_DESIRED, NULL);

Expand Down
36 changes: 24 additions & 12 deletions kame/sys/netinet6/mip6_pktproc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: mip6_pktproc.c,v 1.26 2002/07/23 13:23:23 t-momose Exp $ */
/* $KAME: mip6_pktproc.c,v 1.27 2002/07/24 08:53:36 k-sugyou Exp $ */

/*
* Copyright (C) 2002 WIDE Project. All rights reserved.
Expand Down Expand Up @@ -174,9 +174,9 @@ mip6_ip6mhi_input(m0, ip6mhi, ip6mhilen)
}

int
mip6_ip6mh_create(pktopt_mobility, src, dst, cookie)
mip6_ip6mh_create(pktopt_mobility, dst, src, cookie)
struct ip6_mobility **pktopt_mobility;
struct sockaddr_in6 *src, *dst;
struct sockaddr_in6 *dst, *src;
u_int32_t cookie;
{
struct ip6m_home_test *ip6mh;
Expand All @@ -203,8 +203,8 @@ mip6_ip6mh_create(pktopt_mobility, src, dst, cookie)
ip6mh->ip6mh_type = IP6M_HOME_TEST;
ip6mh->ip6mh_nonce_index = htonl(nonce_index);
ip6mh->ip6mh_mobile_cookie = htonl(cookie);
mip6_create_cookie(&dst->sin6_addr,
&home_nodekey, &home_nonce, &ip6mh->ip6mh_cookie);
mip6_create_cookie(&src->sin6_addr,
&home_nodekey, &home_nonce, ip6mh->ip6mh_cookie);

/* calculate checksum. */
ip6mh->ip6mh_cksum = mip6_cksum(src, dst,
Expand Down Expand Up @@ -281,9 +281,9 @@ mip6_ip6mci_input(m0, ip6mci, ip6mcilen)
}

int
mip6_ip6mc_create(pktopt_mobility, src, dst, cookie)
mip6_ip6mc_create(pktopt_mobility, dst, src, cookie)
struct ip6_mobility **pktopt_mobility;
struct sockaddr_in6 *src, *dst;
struct sockaddr_in6 *dst, *src;
u_int32_t cookie;
{
struct ip6m_careof_test *ip6mc;
Expand Down Expand Up @@ -312,7 +312,7 @@ mip6_ip6mc_create(pktopt_mobility, src, dst, cookie)
ip6mc->ip6mc_mobile_cookie = htonl(cookie);
mip6_create_cookie(&dst->sin6_addr,
&careof_nodekey, &careof_nonce,
&ip6mc->ip6mc_cookie);
ip6mc->ip6mc_cookie);

/* calculate checksum. */
ip6mc->ip6mc_cksum = mip6_cksum(src, dst,
Expand Down Expand Up @@ -1387,6 +1387,7 @@ mip6_ip6mu_create(pktopt_mobility, src, dst, sc)
int bu_size, nonce_size, auth_size;
struct mip6_bu *mbu, *hrmbu;
int need_rr = 0;
struct sockaddr_in6 *busrc_sa;
SHA1_CTX sha1_ctx;
HMAC_CTX hmac_ctx;
u_int8_t key_bu[SHA1_RESULTLEN]; /* Stated as 'Kbu' in the spec */
Expand Down Expand Up @@ -1551,33 +1552,44 @@ printf("MN: Care-of Cookie: %*D\n", sizeof(mbu->mbu_careof_cookie), (caddr_t)&mb
#endif
/* Calculate K_bu */
SHA1Init(&sha1_ctx);
SHA1Update(&sha1_ctx, (caddr_t)&mbu->mbu_home_cookie,
SHA1Update(&sha1_ctx, (caddr_t)mbu->mbu_home_cookie,
sizeof(mbu->mbu_home_cookie));
SHA1Update(&sha1_ctx, (caddr_t)&mbu->mbu_careof_cookie,
SHA1Update(&sha1_ctx, (caddr_t)mbu->mbu_careof_cookie,
sizeof(mbu->mbu_careof_cookie));
SHA1Final(key_bu, &sha1_ctx);
#if RR_DBG
printf("MN: K_bu: %*D\n", sizeof(key_bu), key_bu, ":");
#endif

if (mbu->mbu_fsm_state == MIP6_BU_FSM_STATE_BOUND)
busrc_sa = &mbu->mbu_haddr;
else
busrc_sa = &mbu->mbu_coa;

/* Calculate authenticator (5.5.6) */
/* MAC_Kbu(coa, | cn | BU) */
hmac_init(&hmac_ctx, key_bu, sizeof(key_bu), HMAC_SHA1);
hmac_loop(&hmac_ctx, (u_int8_t *)&mbu->mbu_coa.sin6_addr,
sizeof(mbu->mbu_coa.sin6_addr));
hmac_loop(&hmac_ctx, (u_int8_t *)&busrc_sa->sin6_addr,
sizeof(busrc_sa->sin6_addr));
#if RR_DBG
printf("MN: Auth: %*D\n", sizeof(mbu->mbu_coa.sin6_addr), &mbu->mbu_coa.sin6_addr, ":");
#endif
hmac_loop(&hmac_ctx, (u_int8_t *)&dst->sin6_addr,
sizeof(dst->sin6_addr));
#if RR_DBG
printf("MN: Auth: %*D\n", sizeof(dst->sin6_addr), &dst->sin6_addr, ":");
#endif
hmac_loop(&hmac_ctx, (u_int8_t *)ip6mu, bu_size + nonce_size);
#if RR_DBG
printf("MN: Auth: %*D\n", bu_size + nonce_size, ip6mu, ":");
#endif
/* Eliminate authdata mobility option to calculate authdata
But it should be included padding area */
if (auth_size > AUTH_SIZE) {
*((u_int8_t *)ip6mu + bu_size + nonce_size + AUTH_SIZE)
= IP6MOPT_PADN;
*((u_int8_t *)ip6mu + bu_size + nonce_size + AUTH_SIZE + 1)
= auth_size - AUTH_SIZE;
hmac_loop(&hmac_ctx,
(u_int8_t *)ip6mu + bu_size + nonce_size
+ AUTH_SIZE, auth_size - AUTH_SIZE);
Expand Down

0 comments on commit e4af002

Please sign in to comment.