1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/*
*
* ===================================
* HARP | Host ATM Research Platform
* ===================================
*
*
* This Host ATM Research Platform ("HARP") file (the "Software") is
* made available by Network Computing Services, Inc. ("NetworkCS")
* "AS IS". NetworkCS does not provide maintenance, improvements or
* support of any kind.
*
* NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
* INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
* SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
* In no event shall NetworkCS be responsible for any damages, including
* but not limited to consequential damages, arising from or relating to
* any use of the Software or related support.
*
* Copyright 1994-1998 Network Computing Services, Inc.
*
* Copies of this Software may be made, however, the above copyright
* notice must be reproduced on all copies.
*
* @(#) $FreeBSD$
*
*/
/*
* IP Over ATM Support
* -------------------
*
* Output IP packets across an ATM VCC
*
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
#include <netatm/port.h>
#include <netatm/queue.h>
#include <netatm/atm.h>
#include <netatm/atm_sys.h>
#include <netatm/atm_sap.h>
#include <netatm/atm_cm.h>
#include <netatm/atm_if.h>
#include <netatm/atm_stack.h>
#include <netatm/atm_pcb.h>
#include <netatm/atm_var.h>
#include <netatm/ipatm/ipatm_var.h>
#include <netatm/ipatm/ipatm_serv.h>
#ifndef lint
__RCSID("@(#) $FreeBSD$");
#endif
/*
* Output an IP Packet
*
* All IP packets output to an ATM interface will be directed here via
* the atm_ifoutput() function. If there is an ATM VCC already setup for
* the destination IP address, then we'll just send the packet to that VCC.
* Otherwise we will have to setup a new VCC, ARPing for the corresponding
* destination ATM hardware address along the way.
*
* Arguments:
* ifp pointer to ifnet structure
* m pointer to packet buffer chain to be output
* dst pointer to packet's IP destination address
*
* Returns:
* 0 packet "output" was successful
* errno output failed - reason indicated
*
*/
int
ipatm_ifoutput(ifp, m, dst)
struct ifnet *ifp;
KBuffer *m;
struct sockaddr *dst;
{
struct ipvcc *ivp;
int err = 0;
#ifdef DIAGNOSTIC
if (ipatm_print) {
atm_pdu_print(m, "ipatm_ifoutput");
}
#endif
/*
* See if we've already got an appropriate VCC
*/
ivp = ipatm_iptovc((struct sockaddr_in *)dst, (struct atm_nif *)ifp);
if (ivp) {
/*
* Reset idle timer
*/
ivp->iv_idle = 0;
/*
* Can we use this VCC now??
*/
if ((ivp->iv_state == IPVCC_ACTIVE) &&
(ivp->iv_flags & IVF_MAPOK)) {
/*
* OK, now send packet
*/
err = atm_cm_cpcs_data(ivp->iv_conn, m);
if (err) {
/*
* Output problem, drop packet
*/
KB_FREEALL(m);
}
} else {
/*
* VCC is unavailable for data packets. Queue packet
* for now, but only maintain a queue length of one.
*/
if (ivp->iv_queue)
KB_FREEALL(ivp->iv_queue);
ivp->iv_queue = m;
}
} else {
struct in_ifaddr *ia;
#if (defined(BSD) && (BSD < 199306))
extern struct ifnet loif;
#endif
/*
* No VCC to destination
*/
/*
* Is packet for our interface address?
*/
TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) {
if (ia->ia_ifp != ifp)
continue;
if (((struct sockaddr_in *)dst)->sin_addr.s_addr ==
IA_SIN(ia)->sin_addr.s_addr) {
/*
* It's for us - hand packet to loopback driver
*/
(void) if_simloop(ifp, m, dst->sa_family, 0);
goto done;
}
}
/*
* Is this a broadcast packet ??
*/
#if (defined(BSD) && (BSD >= 199306))
if (in_broadcast(((struct sockaddr_in *)dst)->sin_addr, ifp)) {
#else
if (in_broadcast(((struct sockaddr_in *)dst)->sin_addr)) {
#endif
struct ip_nif *inp;
int s;
/*
* If interface server exists and provides broadcast
* services, then let it deal with this packet
*/
s = splnet();
for (inp = ipatm_nif_head; inp; inp = inp->inf_next) {
if (inp->inf_nif == (struct atm_nif *)ifp)
break;
}
(void) splx(s);
if ((inp == NULL) ||
(inp->inf_serv == NULL) ||
(inp->inf_serv->is_bcast_output == NULL)) {
KB_FREEALL(m);
err = EADDRNOTAVAIL;
goto done;
}
err = (*inp->inf_serv->is_bcast_output)(inp, m);
goto done;
}
/*
* How about a multicast packet ??
*/
if (IN_MULTICAST(ntohl(SATOSIN(dst)->sin_addr.s_addr))) {
/*
* Multicast isn't currently supported
*/
KB_FREEALL(m);
err = EADDRNOTAVAIL;
goto done;
}
/*
* Well, I guess we need to create an SVC to the destination
*/
if ((err = ipatm_createsvc(ifp, AF_INET,
(caddr_t)&((struct sockaddr_in *)dst)->sin_addr,
&ivp)) == 0) {
/*
* SVC open is proceeding, queue packet
*/
ivp->iv_queue = m;
} else {
/*
* SVC open failed, release buffers and return
*/
KB_FREEALL(m);
}
}
done:
return (err);
}
|