remove setjmp
[unix-history] / usr / src / sys / netns / ns_output.c
CommitLineData
8ae0e4b4 1/*
240edf1f
KS
2 * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
3 * All rights reserved.
8ae0e4b4 4 *
240edf1f 5 * Redistribution and use in source and binary forms are permitted
616d42db
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
240edf1f 16 *
fe0fdb83 17 * @(#)ns_output.c 7.6 (Berkeley) %G%
8ae0e4b4 18 */
91fdd342
KS
19
20#include "param.h"
bf8d7cff 21#include "malloc.h"
91fdd342
KS
22#include "mbuf.h"
23#include "errno.h"
24#include "socket.h"
25#include "socketvar.h"
26
27#include "../net/if.h"
28#include "../net/route.h"
29
30#include "ns.h"
31#include "ns_if.h"
32#include "idp.h"
33#include "idp_var.h"
34
35#ifdef vax
36#include "../vax/mtpr.h"
37#endif
6bbc5804
KS
38int ns_hold_output = 0;
39int ns_copy_output = 0;
40int ns_output_cnt = 0;
91fdd342
KS
41struct mbuf *ns_lastout;
42
91fdd342
KS
43ns_output(m0, ro, flags)
44 struct mbuf *m0;
45 struct route *ro;
46 int flags;
47{
48 register struct idp *idp = mtod(m0, struct idp *);
d0c6cd85 49 register struct ifnet *ifp = 0;
f97be0c9 50 int error = 0;
91fdd342
KS
51 struct route idproute;
52 struct sockaddr_ns *dst;
53 extern int idpcksum;
54
5fe5db7d
KS
55 if (ns_hold_output) {
56 if (ns_lastout) {
8011f5df 57 (void)m_free(ns_lastout);
91fdd342 58 }
f97be0c9 59 ns_lastout = m_copy(m0, 0, (int)M_COPYALL);
91fdd342 60 }
91fdd342
KS
61 /*
62 * Route packet.
63 */
64 if (ro == 0) {
65 ro = &idproute;
66 bzero((caddr_t)ro, sizeof (*ro));
67 }
68 dst = (struct sockaddr_ns *)&ro->ro_dst;
69 if (ro->ro_rt == 0) {
70 dst->sns_family = AF_NS;
4dcdd98e 71 dst->sns_len = sizeof (*dst);
91fdd342 72 dst->sns_addr = idp->idp_dna;
5fe5db7d 73 dst->sns_addr.x_port = 0;
91fdd342
KS
74 /*
75 * If routing to interface only,
76 * short circuit routing lookup.
77 */
78 if (flags & NS_ROUTETOIF) {
d0c6cd85 79 struct ns_ifaddr *ia = ns_iaonnetof(&idp->idp_dna);
b8a7d828 80
91fdd342
KS
81 if (ia == 0) {
82 error = ENETUNREACH;
83 goto bad;
84 }
85 ifp = ia->ia_ifp;
86 goto gotif;
87 }
88 rtalloc(ro);
89 } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
90 /*
91 * The old route has gone away; try for a new one.
92 */
93 rtfree(ro->ro_rt);
e89cd9c7 94 ro->ro_rt = NULL;
91fdd342
KS
95 rtalloc(ro);
96 }
97 if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
98 error = ENETUNREACH;
99 goto bad;
100 }
101 ro->ro_rt->rt_use++;
102 if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
4dcdd98e 103 dst = (struct sockaddr_ns *)ro->ro_rt->rt_gateway;
91fdd342
KS
104gotif:
105
106 /*
107 * Look for multicast addresses and
108 * and verify user is allowed to send
109 * such a packet.
110 */
111 if (dst->sns_addr.x_host.c_host[0]&1) {
112 if ((ifp->if_flags & IFF_BROADCAST) == 0) {
113 error = EADDRNOTAVAIL;
114 goto bad;
115 }
116 if ((flags & NS_ALLOWBROADCAST) == 0) {
117 error = EACCES;
118 goto bad;
119 }
120 }
121
122 if (htons(idp->idp_len) <= ifp->if_mtu) {
123 ns_output_cnt++;
d0c6cd85
KS
124 if (ns_copy_output) {
125 ns_watch_output(m0, ifp);
126 }
fe0fdb83
KS
127 error = (*ifp->if_output)(ifp, m0,
128 (struct sockaddr *)dst, ro->ro_rt);
91fdd342
KS
129 goto done;
130 } else error = EMSGSIZE;
131
132
133bad:
d0c6cd85
KS
134 if (ns_copy_output) {
135 ns_watch_output(m0, ifp);
136 }
91fdd342
KS
137 m_freem(m0);
138done:
4dcdd98e 139 if (ro == &idproute && (flags & NS_ROUTETOIF) == 0 && ro->ro_rt) {
91fdd342 140 RTFREE(ro->ro_rt);
4dcdd98e
KS
141 ro->ro_rt = 0;
142 }
91fdd342
KS
143 return (error);
144}