Use sockaddr_in6_init().

This commit is contained in:
dyoung 2007-11-10 00:14:31 +00:00
parent c44fbd164e
commit 5121052595
5 changed files with 31 additions and 77 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6_ifattach.c,v 1.74 2007/11/01 20:33:56 dyoung Exp $ */
/* $NetBSD: in6_ifattach.c,v 1.75 2007/11/10 00:14:31 dyoung Exp $ */
/* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */
/*
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.74 2007/11/01 20:33:56 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.75 2007/11/10 00:14:31 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -563,9 +563,7 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct ifnet *altifp)
if (in6_setscope(&ifra.ifra_addr.sin6_addr, ifp, NULL))
return -1;
ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
ifra.ifra_prefixmask.sin6_family = AF_INET6;
ifra.ifra_prefixmask.sin6_addr = in6mask64;
sockaddr_in6_init(&ifra.ifra_prefixmask, &in6mask64, 0, 0, 0);
/* link-local addresses should NEVER expire. */
ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
@ -658,21 +656,15 @@ in6_ifattach_loopback(struct ifnet *ifp)
*/
strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
ifra.ifra_prefixmask.sin6_family = AF_INET6;
ifra.ifra_prefixmask.sin6_addr = in6mask128;
sockaddr_in6_init(&ifra.ifra_prefixmask, &in6mask128, 0, 0, 0);
/*
* Always initialize ia_dstaddr (= broadcast address) to loopback
* address. Follows IPv4 practice - see in_ifinit().
*/
ifra.ifra_dstaddr.sin6_len = sizeof(struct sockaddr_in6);
ifra.ifra_dstaddr.sin6_family = AF_INET6;
ifra.ifra_dstaddr.sin6_addr = in6addr_loopback;
sockaddr_in6_init(&ifra.ifra_dstaddr, &in6addr_loopback, 0, 0, 0);
ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
ifra.ifra_addr.sin6_family = AF_INET6;
ifra.ifra_addr.sin6_addr = in6addr_loopback;
sockaddr_in6_init(&ifra.ifra_addr, &in6addr_loopback, 0, 0, 0);
/* the loopback address should NEVER expire. */
ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6_pcb.c,v 1.88 2007/07/19 20:48:56 dyoung Exp $ */
/* $NetBSD: in6_pcb.c,v 1.89 2007/11/10 00:14:31 dyoung Exp $ */
/* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.88 2007/07/19 20:48:56 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.89 2007/11/10 00:14:31 dyoung Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -529,11 +529,7 @@ in6_setsockaddr(struct in6pcb *in6p, struct mbuf *nam)
nam->m_len = sizeof(*sin6);
sin6 = mtod(nam, struct sockaddr_in6 *);
bzero((void *)sin6, sizeof(*sin6));
sin6->sin6_family = AF_INET6;
sin6->sin6_len = sizeof(struct sockaddr_in6);
sin6->sin6_port = in6p->in6p_lport;
sin6->sin6_addr = in6p->in6p_laddr;
sockaddr_in6_init(sin6, &in6p->in6p_laddr, in6p->in6p_lport, 0, 0);
(void)sa6_recoverscope(sin6); /* XXX: should catch errors */
}
@ -547,11 +543,7 @@ in6_setpeeraddr(struct in6pcb *in6p, struct mbuf *nam)
nam->m_len = sizeof(*sin6);
sin6 = mtod(nam, struct sockaddr_in6 *);
bzero((void *)sin6, sizeof(*sin6));
sin6->sin6_family = AF_INET6;
sin6->sin6_len = sizeof(struct sockaddr_in6);
sin6->sin6_port = in6p->in6p_fport;
sin6->sin6_addr = in6p->in6p_faddr;
sockaddr_in6_init(sin6, &in6p->in6p_faddr, in6p->in6p_fport, 0, 0);
(void)sa6_recoverscope(sin6); /* XXX: should catch errors */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip6_mroute.c,v 1.84 2007/11/01 20:33:57 dyoung Exp $ */
/* $NetBSD: ip6_mroute.c,v 1.85 2007/11/10 00:14:32 dyoung Exp $ */
/* $KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $ */
/*
@ -117,7 +117,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.84 2007/11/01 20:33:57 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.85 2007/11/10 00:14:32 dyoung Exp $");
#include "opt_inet.h"
#include "opt_mrouting.h"
@ -1172,10 +1172,7 @@ ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m)
/*
* Send message to routing daemon
*/
(void)memset(&sin6, 0, sizeof(sin6));
sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = ip6->ip6_src;
sockaddr_in6_init(&sin6, &ip6->ip6_src, 0, 0, 0);
im = NULL;
oim = NULL;
@ -1233,12 +1230,10 @@ ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m)
/* insert new entry at head of hash chain */
bzero(rt, sizeof(*rt));
rt->mf6c_origin.sin6_family = AF_INET6;
rt->mf6c_origin.sin6_len = sizeof(struct sockaddr_in6);
rt->mf6c_origin.sin6_addr = ip6->ip6_src;
rt->mf6c_mcastgrp.sin6_family = AF_INET6;
rt->mf6c_mcastgrp.sin6_len = sizeof(struct sockaddr_in6);
rt->mf6c_mcastgrp.sin6_addr = ip6->ip6_dst;
sockaddr_in6_init(&rt->mf6c_origin, &ip6->ip6_src,
0, 0, 0);
sockaddr_in6_init(&rt->mf6c_mcastgrp, &ip6->ip6_dst,
0, 0, 0);
rt->mf6c_expire = UPCALL_EXPIRE;
n6expire[hash]++;
rt->mf6c_parent = MF6C_INCOMPLETE_PARENT;
@ -1576,10 +1571,7 @@ phyint_send(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m)
* Does not have to check source info, as it's alreay covered by
* ip6_input
*/
memset(&dst6, 0, sizeof(dst6));
dst6.sin6_family = AF_INET6;
dst6.sin6_len = sizeof(struct sockaddr_in6);
dst6.sin6_addr = ip6->ip6_dst;
sockaddr_in6_init(&dst6, &ip6->ip6_dst, 0, 0, 0);
IN6_LOOKUP_MULTI(ip6->ip6_dst, ifp, in6m);
if (in6m != NULL) {
@ -1668,10 +1660,7 @@ register_send(struct ip6_hdr *ip6, struct mif6 *mif, struct mbuf *m)
/*
* Send message to routing daemon
*/
(void)memset(&sin6, 0, sizeof(sin6));
sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = ip6->ip6_src;
sockaddr_in6_init(&sin6, &ip6->ip6_src, 0, 0, 0);
im6 = mtod(mm, struct mrt6msg *);
im6->im6_msgtype = MRT6MSG_WHOLEPKT;

View File

@ -1,4 +1,4 @@
/* $NetBSD: nd6_nbr.c,v 1.80 2007/08/30 02:17:38 dyoung Exp $ */
/* $NetBSD: nd6_nbr.c,v 1.81 2007/11/10 00:14:32 dyoung Exp $ */
/* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */
/*
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.80 2007/08/30 02:17:38 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.81 2007/11/10 00:14:32 dyoung Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -215,10 +215,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len)
struct rtentry *rt;
struct sockaddr_in6 tsin6;
memset(&tsin6, 0, sizeof(tsin6));
tsin6.sin6_len = sizeof(struct sockaddr_in6);
tsin6.sin6_family = AF_INET6;
tsin6.sin6_addr = taddr6;
sockaddr_in6_init(&tsin6, &taddr6, 0, 0, 0);
rt = rtalloc1((struct sockaddr *)&tsin6, 0);
if (rt && (rt->rt_flags & RTF_ANNOUNCE) != 0 &&
@ -451,10 +448,7 @@ nd6_ns_output(struct ifnet *ifp, const struct in6_addr *daddr6,
int error;
struct sockaddr_in6 dst_sa;
bzero(&dst_sa, sizeof(dst_sa));
dst_sa.sin6_family = AF_INET6;
dst_sa.sin6_len = sizeof(dst_sa);
dst_sa.sin6_addr = ip6->ip6_dst;
sockaddr_in6_init(&dst_sa, &ip6->ip6_dst, 0, 0, 0);
src = in6_selectsrc(&dst_sa, NULL,
NULL, &ro, NULL, NULL, &error);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nd6_rtr.c,v 1.68 2007/11/01 20:33:58 dyoung Exp $ */
/* $NetBSD: nd6_rtr.c,v 1.69 2007/11/10 00:14:32 dyoung Exp $ */
/* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $ */
/*
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.68 2007/11/01 20:33:58 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.69 2007/11/10 00:14:32 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -316,9 +316,8 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len)
}
bzero(&pr, sizeof(pr));
pr.ndpr_prefix.sin6_family = AF_INET6;
pr.ndpr_prefix.sin6_len = sizeof(pr.ndpr_prefix);
pr.ndpr_prefix.sin6_addr = pi->nd_opt_pi_prefix;
sockaddr_in6_init(&pr.ndpr_prefix,
&pi->nd_opt_pi_prefix, 0, 0, 0);
pr.ndpr_ifp = (struct ifnet *)m->m_pkthdr.rcvif;
pr.ndpr_raf_onlink = (pi->nd_opt_pi_flags_reserved &
@ -1633,15 +1632,8 @@ nd6_prefix_offlink(struct nd_prefix *pr)
return (EEXIST);
}
bzero(&sa6, sizeof(sa6));
sa6.sin6_family = AF_INET6;
sa6.sin6_len = sizeof(sa6);
bcopy(&pr->ndpr_prefix.sin6_addr, &sa6.sin6_addr,
sizeof(struct in6_addr));
bzero(&mask6, sizeof(mask6));
mask6.sin6_family = AF_INET6;
mask6.sin6_len = sizeof(sa6);
bcopy(&pr->ndpr_mask, &mask6.sin6_addr, sizeof(struct in6_addr));
sockaddr_in6_init(&sa6, &pr->ndpr_prefix.sin6_addr, 0, 0, 0);
sockaddr_in6_init(&mask6, &pr->ndpr_mask, 0, 0, 0);
error = rtrequest(RTM_DELETE, (struct sockaddr *)&sa6, NULL,
(struct sockaddr *)&mask6, 0, &rt);
if (error == 0) {
@ -1773,10 +1765,8 @@ in6_ifadd(struct nd_prefixctl *pr, int mcast)
* for safety.
*/
strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
ifra.ifra_addr.sin6_family = AF_INET6;
ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
sockaddr_in6_init(&ifra.ifra_addr, &pr->ndpr_prefix.sin6_addr, 0, 0, 0);
/* prefix */
ifra.ifra_addr.sin6_addr = pr->ndpr_prefix.sin6_addr;
ifra.ifra_addr.sin6_addr.s6_addr32[0] &= mask.s6_addr32[0];
ifra.ifra_addr.sin6_addr.s6_addr32[1] &= mask.s6_addr32[1];
ifra.ifra_addr.sin6_addr.s6_addr32[2] &= mask.s6_addr32[2];
@ -1793,10 +1783,7 @@ in6_ifadd(struct nd_prefixctl *pr, int mcast)
(ib->ia_addr.sin6_addr.s6_addr32[3] & ~mask.s6_addr32[3]);
/* new prefix mask. */
ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
ifra.ifra_prefixmask.sin6_family = AF_INET6;
bcopy(&mask, &ifra.ifra_prefixmask.sin6_addr,
sizeof(ifra.ifra_prefixmask.sin6_addr));
sockaddr_in6_init(&ifra.ifra_prefixmask, &mask, 0, 0, 0);
/* lifetimes */
ifra.ifra_lifetime.ia6t_vltime = pr->ndpr_vltime;