2016-12-08 08:16:33 +03:00
|
|
|
/* $NetBSD: ddp_output.c,v 1.20 2016/12/08 05:16:33 ozaki-r Exp $ */
|
1997-04-03 01:31:01 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1990,1991 Regents of The University of Michigan.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and
|
|
|
|
* its documentation for any purpose and without fee is hereby granted,
|
|
|
|
* provided that the above copyright notice appears in all copies and
|
|
|
|
* that both that copyright notice and this permission notice appear
|
|
|
|
* in supporting documentation, and that the name of The University
|
|
|
|
* of Michigan not be used in advertising or publicity pertaining to
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
* permission. This software is supplied as is without expressed or
|
|
|
|
* implied warranties of any kind.
|
|
|
|
*
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
*
|
|
|
|
* Research Systems Unix Group
|
|
|
|
* The University of Michigan
|
|
|
|
* c/o Wesley Craig
|
|
|
|
* 535 W. William Street
|
|
|
|
* Ann Arbor, Michigan
|
|
|
|
* +1-313-764-2278
|
|
|
|
* netatalk@umich.edu
|
|
|
|
*/
|
|
|
|
|
2001-11-13 03:00:58 +03:00
|
|
|
#include <sys/cdefs.h>
|
2016-12-08 08:16:33 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ddp_output.c,v 1.20 2016/12/08 05:16:33 ozaki-r Exp $");
|
2001-11-13 03:00:58 +03:00
|
|
|
|
1997-04-03 01:31:01 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#undef s_net
|
|
|
|
|
|
|
|
#include <netatalk/at.h>
|
|
|
|
#include <netatalk/at_var.h>
|
|
|
|
#include <netatalk/ddp.h>
|
|
|
|
#include <netatalk/ddp_var.h>
|
|
|
|
#include <netatalk/at_extern.h>
|
|
|
|
|
|
|
|
int ddp_cksum = 1;
|
|
|
|
|
|
|
|
int
|
2016-01-21 00:59:19 +03:00
|
|
|
ddp_output(struct mbuf *m, struct ddpcb *ddp)
|
1997-04-03 01:31:01 +04:00
|
|
|
{
|
|
|
|
struct ddpehdr *deh;
|
|
|
|
|
2003-05-28 02:27:21 +04:00
|
|
|
M_PREPEND(m, sizeof(struct ddpehdr), M_DONTWAIT);
|
|
|
|
if (!m)
|
|
|
|
return (ENOBUFS);
|
1997-04-03 01:31:01 +04:00
|
|
|
|
|
|
|
deh = mtod(m, struct ddpehdr *);
|
|
|
|
deh->deh_pad = 0;
|
|
|
|
deh->deh_hops = 0;
|
|
|
|
|
|
|
|
deh->deh_len = m->m_pkthdr.len;
|
|
|
|
|
|
|
|
deh->deh_dnet = ddp->ddp_fsat.sat_addr.s_net;
|
|
|
|
deh->deh_dnode = ddp->ddp_fsat.sat_addr.s_node;
|
|
|
|
deh->deh_dport = ddp->ddp_fsat.sat_port;
|
|
|
|
deh->deh_snet = ddp->ddp_lsat.sat_addr.s_net;
|
|
|
|
deh->deh_snode = ddp->ddp_lsat.sat_addr.s_node;
|
|
|
|
deh->deh_sport = ddp->ddp_lsat.sat_port;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The checksum calculation is done after all of the other bytes have
|
|
|
|
* been filled in.
|
|
|
|
*/
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
if (ddp_cksum)
|
1997-04-03 01:31:01 +04:00
|
|
|
deh->deh_sum = at_cksum(m, sizeof(int));
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
else
|
1997-04-03 01:31:01 +04:00
|
|
|
deh->deh_sum = 0;
|
|
|
|
deh->deh_bytes = htonl(deh->deh_bytes);
|
|
|
|
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
return ddp_route(m, &ddp->ddp_route);
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
u_short
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
at_cksum(struct mbuf *m, int skip)
|
1997-04-03 01:31:01 +04:00
|
|
|
{
|
|
|
|
u_char *data, *end;
|
|
|
|
u_long cksum = 0;
|
|
|
|
|
|
|
|
for (; m; m = m->m_next) {
|
|
|
|
for (data = mtod(m, u_char *), end = data + m->m_len;
|
|
|
|
data < end; data++) {
|
|
|
|
if (skip) {
|
|
|
|
skip--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cksum = (cksum + *data) << 1;
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
if (cksum & 0x00010000)
|
1997-04-03 01:31:01 +04:00
|
|
|
cksum++;
|
|
|
|
cksum &= 0x0000ffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cksum == 0) {
|
|
|
|
cksum = 0x0000ffff;
|
|
|
|
}
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
return (u_short)cksum;
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
ddp_route(struct mbuf *m, struct route *ro)
|
1997-04-03 01:31:01 +04:00
|
|
|
{
|
2007-12-20 22:53:29 +03:00
|
|
|
struct rtentry *rt;
|
1997-04-03 01:31:01 +04:00
|
|
|
struct sockaddr_at gate;
|
|
|
|
struct elaphdr *elh;
|
|
|
|
struct at_ifaddr *aa = NULL;
|
|
|
|
struct ifnet *ifp = NULL;
|
2012-01-31 13:53:44 +04:00
|
|
|
uint16_t net;
|
|
|
|
uint8_t loopback = 0;
|
2016-12-08 08:16:33 +03:00
|
|
|
int error;
|
1997-04-03 01:31:01 +04:00
|
|
|
|
2008-04-06 22:46:56 +04:00
|
|
|
if ((rt = rtcache_validate(ro)) != NULL && (ifp = rt->rt_ifp) != NULL) {
|
2012-01-31 13:53:44 +04:00
|
|
|
const struct sockaddr_at *dst = satocsat(rtcache_getdst(ro));
|
|
|
|
uint16_t dnet = dst->sat_addr.s_net;
|
|
|
|
uint8_t dnode = dst->sat_addr.s_node;
|
2007-12-20 22:53:29 +03:00
|
|
|
net = satosat(rt->rt_gateway)->sat_addr.s_net;
|
2012-01-31 13:53:44 +04:00
|
|
|
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
TAILQ_FOREACH(aa, &at_ifaddr, aa_list) {
|
2012-01-31 13:53:44 +04:00
|
|
|
if (ntohs(net) >= ntohs(aa->aa_firstnet) &&
|
1997-04-03 01:31:01 +04:00
|
|
|
ntohs(net) <= ntohs(aa->aa_lastnet)) {
|
2012-01-31 13:53:44 +04:00
|
|
|
/* Are we talking to ourselves? */
|
|
|
|
if (dnet == aa->aa_addr.sat_addr.s_net &&
|
|
|
|
dnode == aa->aa_addr.sat_addr.s_node) {
|
|
|
|
/* If to us, redirect to lo0. */
|
|
|
|
ifp = lo0ifp;
|
|
|
|
}
|
|
|
|
/* Or is it a broadcast? */
|
|
|
|
else if (dnet == aa->aa_addr.sat_addr.s_net &&
|
|
|
|
dnode == 255) {
|
|
|
|
/* If broadcast, loop back a copy. */
|
|
|
|
loopback = 1;
|
|
|
|
}
|
1997-04-03 01:31:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aa == NULL) {
|
2012-01-31 13:53:44 +04:00
|
|
|
#ifdef NETATALKDEBUG
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
printf("%s: no address found\n", __func__);
|
2012-01-31 13:53:44 +04:00
|
|
|
#endif
|
1997-04-03 01:31:01 +04:00
|
|
|
m_freem(m);
|
2016-12-08 08:16:33 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* There are several places in the kernel where data is added to
|
|
|
|
* an mbuf without ensuring that the mbuf pointer is aligned.
|
|
|
|
* This is bad for transition routing, since phase 1 and phase 2
|
|
|
|
* packets end up poorly aligned due to the three byte elap header.
|
|
|
|
*/
|
|
|
|
if (!(aa->aa_flags & AFA_PHASE2)) {
|
2003-05-28 02:27:21 +04:00
|
|
|
M_PREPEND(m, SZ_ELAPHDR, M_DONTWAIT);
|
2016-12-08 08:16:33 +03:00
|
|
|
if (m == NULL) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto out;
|
|
|
|
}
|
1997-04-03 01:31:01 +04:00
|
|
|
|
|
|
|
elh = mtod(m, struct elaphdr *);
|
|
|
|
elh->el_snode = satosat(&aa->aa_addr)->sat_addr.s_node;
|
|
|
|
elh->el_type = ELAP_DDPEXTEND;
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
if (ntohs(satocsat(rtcache_getdst(ro))->sat_addr.s_net) >=
|
1997-04-03 01:31:01 +04:00
|
|
|
ntohs(aa->aa_firstnet) &&
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
ntohs(satocsat(rtcache_getdst(ro))->sat_addr.s_net) <=
|
1997-04-03 01:31:01 +04:00
|
|
|
ntohs(aa->aa_lastnet)) {
|
2012-01-31 13:53:44 +04:00
|
|
|
elh->el_dnode =
|
|
|
|
satocsat(rtcache_getdst(ro))->sat_addr.s_node;
|
1997-04-03 01:31:01 +04:00
|
|
|
} else {
|
|
|
|
elh->el_dnode =
|
2007-12-20 22:53:29 +03:00
|
|
|
satosat(rt->rt_gateway)->sat_addr.s_node;
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
|
|
|
}
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
if (ntohs(satocsat(rtcache_getdst(ro))->sat_addr.s_net) >=
|
1997-04-03 01:31:01 +04:00
|
|
|
ntohs(aa->aa_firstnet) &&
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
ntohs(satocsat(rtcache_getdst(ro))->sat_addr.s_net) <=
|
1997-04-03 01:31:01 +04:00
|
|
|
ntohs(aa->aa_lastnet)) {
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
gate = *satocsat(rtcache_getdst(ro));
|
1997-04-03 01:31:01 +04:00
|
|
|
} else {
|
2007-12-20 22:53:29 +03:00
|
|
|
gate = *satosat(rt->rt_gateway);
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|
2007-12-20 22:53:29 +03:00
|
|
|
rt->rt_use++;
|
1997-04-03 01:31:01 +04:00
|
|
|
|
1999-03-27 04:24:49 +03:00
|
|
|
#if IFA_STATS
|
|
|
|
aa->aa_ifa.ifa_data.ifad_outbytes += m->m_pkthdr.len;
|
|
|
|
#endif
|
|
|
|
|
1997-04-03 01:31:01 +04:00
|
|
|
/* XXX */
|
2012-01-31 13:53:44 +04:00
|
|
|
if (loopback && rtcache_getdst(ro)->sa_family == AF_APPLETALK) {
|
|
|
|
struct mbuf *copym = m_copypacket(m, M_DONTWAIT);
|
|
|
|
|
|
|
|
#ifdef NETATALKDEBUG
|
|
|
|
printf("Looping back (not AARP).\n");
|
|
|
|
#endif
|
|
|
|
looutput(lo0ifp, copym, rtcache_getdst(ro), NULL);
|
|
|
|
}
|
2016-12-08 08:16:33 +03:00
|
|
|
|
|
|
|
error = if_output_lock(ifp, ifp, m, (struct sockaddr *)&gate, NULL);
|
|
|
|
out:
|
|
|
|
rtcache_unref(rt, ro);
|
|
|
|
return error;
|
1997-04-03 01:31:01 +04:00
|
|
|
}
|