3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/netatm/uni/uniarp_vcm.c,v 1.5 2000/01/17 20:49:55 mks Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/uni/uniarp_vcm.c,v 1.4 2003/08/07 21:54:34 dillon Exp $
31 * ATM Forum UNI Support
32 * ---------------------
34 * UNI ATMARP support (RFC1577) - Virtual Channel Management
38 #include <netproto/atm/kern_include.h>
40 #include <netproto/atm/ipatm/ipatm_var.h>
41 #include <netproto/atm/ipatm/ipatm_serv.h>
42 #include "uniip_var.h"
47 static struct attr_llc uniarp_llc = {
52 {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x06}
56 static struct t_atm_cause uniarp_cause = {
59 T_ATM_CAUSE_TEMPORARY_FAILURE,
65 * Process a new PVC requiring ATMARP support
67 * This function is called after IP/ATM has successfully opened a PVC which
68 * requires ATMARP support. We will send an InATMARP request over the PVC
69 * to elicit a response from the PVC's ATMARP peer informing us of its
70 * network address. This information will also be used by IP/ATM in order
71 * to complete its address-to-VC mapping table.
74 * ivp pointer to PVC's IPVCC control block
77 * MAP_PROCEEDING - OK so far, querying for peer's mapping
78 * MAP_FAILED - error, unable to allocate resources
89 ATM_DEBUG1("uniarp_pvcopen: ivp=%p\n", ivp);
91 ivp->iv_arpent = NULL;
96 if ((ivp->iv_flags & IVF_LLC) == 0)
102 uip = (struct uniip *)ivp->iv_ipnif->inf_isintf;
107 * Get an arp map entry
109 uap = (struct uniarp *)atm_allocate(&uniarp_pool);
114 * Create our CM connection
116 err = atm_cm_addllc(&uniarp_endpt, ivp, &uniarp_llc,
117 ivp->iv_conn, &ivp->iv_arpconn);
120 * We don't take no (or maybe) for an answer
122 if (ivp->iv_arpconn) {
123 (void) atm_cm_release(ivp->iv_arpconn, &uniarp_cause);
124 ivp->iv_arpconn = NULL;
126 atm_free((caddr_t)uap);
131 * Get map entry set up
134 uap->ua_dstatm.address_format = T_ATM_ABSENT;
135 uap->ua_dstatmsub.address_format = T_ATM_ABSENT;
139 * Put ivp on arp entry chain
141 LINK2TAIL(ivp, struct ipvcc, uap->ua_ivp, iv_arpnext);
142 ivp->iv_arpent = (struct arpmap *)uap;
145 * Put arp entry on pvc chain
147 LINK2TAIL(uap, struct uniarp, uniarp_pvctab, ua_next);
150 * Send Inverse ATMARP request
152 (void) uniarp_inarp_req(uip, &uap->ua_dstatm, &uap->ua_dstatmsub, ivp);
157 uap->ua_aging = UNIARP_REVALID_AGE;
160 return (MAP_PROCEEDING);
165 * Process a new outgoing SVC requiring ATMARP support
167 * This function is called by the IP/ATM module to resolve a destination
168 * IP address to an ATM address in order to open an SVC to that destination.
169 * If a valid mapping is already in our cache, then we just tell the caller
170 * about it and that's that. Otherwise, we have to allocate a new arp entry
171 * and issue a query for the mapping.
174 * ivp pointer to SVC's IPVCC control block
175 * dst pointer to destination IP address
178 * MAP_VALID - Got the answer, returned via iv_arpent field.
179 * MAP_PROCEEDING - OK so far, querying for peer's mapping
180 * MAP_FAILED - error, unable to allocate resources
184 uniarp_svcout(ivp, dst)
192 ATM_DEBUG2("uniarp_svcout: ivp=%p,dst=0x%x\n", ivp, dst->s_addr);
194 ivp->iv_arpent = NULL;
199 uip = (struct uniip *)ivp->iv_ipnif->inf_isintf;
206 * Lookup IP destination address
208 UNIARP_LOOKUP(dst->s_addr, uap);
212 * We've got an entry, verify interface
214 if (uap->ua_intf != uip) {
220 * Chain this vcc onto entry
222 LINK2TAIL(ivp, struct ipvcc, uap->ua_ivp, iv_arpnext);
223 ivp->iv_arpent = (struct arpmap *)uap;
224 uap->ua_flags |= UAF_USED;
226 if (uap->ua_flags & UAF_VALID) {
228 * Entry is valid, we're done
234 * We're already looking for this address
237 return (MAP_PROCEEDING);
242 * No info in the cache. If we're the server, then
243 * we're already authoritative, so just deny request.
244 * If we're a client but the server VCC isn't open we
245 * also deny the request.
247 if (uip->uip_arpstate != UIAS_CLIENT_ACTIVE) {
253 * We're a client with an open VCC to the server, get a new arp entry
255 uap = (struct uniarp *)atm_allocate(&uniarp_pool);
264 uap->ua_dstip.s_addr = dst->s_addr;
265 uap->ua_dstatm.address_format = T_ATM_ABSENT;
266 uap->ua_dstatm.address_length = 0;
267 uap->ua_dstatmsub.address_format = T_ATM_ABSENT;
268 uap->ua_dstatmsub.address_length = 0;
272 * Link ipvcc to arp entry for later notification
274 LINK2TAIL(ivp, struct ipvcc, uap->ua_ivp, iv_arpnext);
275 ivp->iv_arpent = (struct arpmap *)uap;
276 uap->ua_flags |= UAF_USED;
279 * Add arp entry to table
284 * Issue arp request for this address
286 (void) uniarp_arp_req(uip, dst);
291 UNIARP_TIMER(uap, UNIARP_ARP_RETRY);
294 return (MAP_PROCEEDING);
299 * Process a new incoming SVC requiring ATMARP support
301 * This function is called by the IP/ATM module to resolve a caller's ATM
302 * address to its IP address for an incoming call in order to allow a
303 * bi-directional flow of IP packets on the SVC. If a valid mapping is
304 * already in our cache, then we will use it. Otherwise, we have to allocate
305 * a new arp entry and wait for the SVC to become active so that we can issue
306 * an InATMARP to the peer.
309 * ivp pointer to SVC's IPVCC control block
310 * dst pointer to caller's ATM address
311 * dstsub pointer to caller's ATM subaddress
314 * MAP_VALID - Got the answer, returned via iv_arpent field.
315 * MAP_PROCEEDING - OK so far, querying for peer's mapping
316 * MAP_FAILED - error, unable to allocate resources
320 uniarp_svcin(ivp, dst, dstsub)
327 int found = 0, i, s = splnet();
329 ATM_DEBUG1("uniarp_svcin: ivp=%p\n", ivp);
332 * Clear ARP entry field
334 ivp->iv_arpent = NULL;
339 if ((ivp->iv_flags & IVF_LLC) == 0)
345 uip = (struct uniip *)ivp->iv_ipnif->inf_isintf;
352 * Make sure we're configured as a client or server
354 if (uip->uip_arpstate == UIAS_NOTCONF) {
360 * If we know the caller's ATM address, look it up
363 if (dst->address_format != T_ATM_ABSENT) {
364 for (i = 0; (i < UNIARP_HASHSIZ) && (found == 0); i++) {
365 for (uap = uniarp_arptab[i]; uap; uap = uap->ua_next) {
366 if (ATM_ADDR_EQUAL(dst, &uap->ua_dstatm) &&
367 ATM_ADDR_EQUAL(dstsub, &uap->ua_dstatmsub)){
374 for (uap = uniarp_nomaptab; uap; uap = uap->ua_next) {
375 if (ATM_ADDR_EQUAL(dst, &uap->ua_dstatm) &&
376 ATM_ADDR_EQUAL(dstsub, &uap->ua_dstatmsub))
384 * We've got an entry, verify interface
386 if (uap->ua_intf != uip) {
392 * Chain the vcc onto this entry
394 LINK2TAIL(ivp, struct ipvcc, uap->ua_ivp, iv_arpnext);
395 ivp->iv_arpent = (struct arpmap *)uap;
396 uap->ua_flags |= UAF_USED;
398 if (uap->ua_flags & UAF_VALID) {
400 * Entry is valid, we're done
406 * We're already looking for this address
409 return (MAP_PROCEEDING);
414 * No info in the cache - get a new arp entry
416 uap = (struct uniarp *)atm_allocate(&uniarp_pool);
425 ATM_ADDR_COPY(dst, &uap->ua_dstatm);
426 ATM_ADDR_COPY(dstsub, &uap->ua_dstatmsub);
430 * Link ipvcc to arp entry for later notification
432 LINK2TAIL(ivp, struct ipvcc, uap->ua_ivp, iv_arpnext);
433 ivp->iv_arpent = (struct arpmap *)uap;
434 uap->ua_flags |= UAF_USED;
437 * Add arp entry to 'nomap' table
439 LINK2TAIL(uap, struct uniarp, uniarp_nomaptab, ua_next);
444 * Now we just wait for SVC to become active
446 return (MAP_PROCEEDING);
451 * Process ARP SVC activation notification
453 * This function is called by the IP/ATM module whenever a previously
454 * opened SVC has successfully been connected.
457 * ivp pointer to SVC's IPVCC control block
460 * 0 activation processing successful
461 * errno activation failed - reason indicated
465 uniarp_svcactive(ivp)
471 int err, s = splnet();
473 ATM_DEBUG1("uniarp_svcactive: ivp=%p\n", ivp);
476 uip = (struct uniip *)inp->inf_isintf;
477 uap = (struct uniarp *)ivp->iv_arpent;
480 * First, we need to create our CM connection
482 err = atm_cm_addllc(&uniarp_endpt, ivp, &uniarp_llc,
483 ivp->iv_conn, &ivp->iv_arpconn);
486 * We don't take no (or maybe) for an answer
488 if (ivp->iv_arpconn) {
489 (void) atm_cm_release(ivp->iv_arpconn, &uniarp_cause);
490 ivp->iv_arpconn = NULL;
496 * Is this the client->server vcc??
498 if (uip->uip_arpsvrvcc == ivp) {
501 * Yep, go into the client registration phase
503 uip->uip_arpstate = UIAS_CLIENT_REGISTER;
506 * To register ourselves, RFC1577 says we should wait
507 * around for the server to send us an InATMARP_Request.
508 * However, draft-1577+ just has us send an ATMARP_Request
509 * for our own address. To keep everyone happy, we'll go
510 * with both and see what works!
512 (void) uniarp_arp_req(uip, &(IA_SIN(inp->inf_addr)->sin_addr));
517 UNIIP_ARP_TIMER(uip, 1 * ATM_HZ);
524 * Send an InATMARP_Request on this VCC to find out/notify who's at
525 * the other end. If we're the server, this will start off the
526 * RFC1577 registration procedure. If we're a client, then this
527 * SVC is for user data and it's pretty likely that both ends are
528 * going to be sending packets. So, if we're the caller, we'll be
529 * nice and let the callee know right away who we are. If we're the
530 * callee, let's find out asap the caller's IP address.
532 (void) uniarp_inarp_req(uip, &uap->ua_dstatm, &uap->ua_dstatmsub, ivp);
535 * Start retry timer if entry isn't valid yet
537 if (((uap->ua_flags & UAF_VALID) == 0) &&
538 ((uap->ua_time.ti_flag & TIF_QUEUED) == 0))
539 UNIARP_TIMER(uap, UNIARP_ARP_RETRY);
549 * This function is called just prior to IP/ATM closing a VCC which
550 * supports ATMARP. We'll sever our links to the VCC and then
551 * figure out how much more cleanup we need to do for now.
554 * ivp pointer to VCC's IPVCC control block
568 ATM_DEBUG1("uniarp_vcclose: ivp=%p\n", ivp);
571 * Close our CM connection
573 if (ivp->iv_arpconn) {
574 (void) atm_cm_release(ivp->iv_arpconn, &uniarp_cause);
575 ivp->iv_arpconn = NULL;
581 if ((uap = (struct uniarp *)ivp->iv_arpent) == NULL)
588 * If this is the arpserver VCC, then schedule ourselves to
589 * reopen the connection soon
591 if (uip->uip_arpsvrvcc == ivp) {
592 uip->uip_arpsvrvcc = NULL;
593 uip->uip_arpstate = UIAS_CLIENT_POPEN;
594 UNIIP_ARP_CANCEL(uip);
595 UNIIP_ARP_TIMER(uip, 5 * ATM_HZ);
599 * Remove IP VCC from chain
601 UNLINK(ivp, struct ipvcc, uap->ua_ivp, iv_arpnext);
604 * SVCs and PVCs are handled separately
606 if (ivp->iv_flags & IVF_SVC) {
608 * If the mapping is currently valid or in use, or if there
609 * are other VCCs still using this mapping, we're done for now
611 if ((uap->ua_flags & (UAF_VALID | UAF_LOCKED)) ||
612 (uap->ua_origin >= UAO_PERM) ||
613 (uap->ua_ivp != NULL)) {
621 if (uap->ua_dstip.s_addr == 0) {
622 UNLINK(uap, struct uniarp, uniarp_nomaptab, ua_next);
628 * Remove entry from pvc table
630 UNLINK(uap, struct uniarp, uniarp_pvctab, ua_next);
636 * Finally, free the entry
638 atm_free((caddr_t)uap);
646 * Process ATMARP VCC Connected Notification
649 * toku owner's connection token (ipvcc protocol block)
656 uniarp_connected(toku)
661 * Since we only do atm_cm_addllc()'s on active connections,
662 * we should never get called here...
664 panic("uniarp_connected");
669 * Process ATMARP VCC Cleared Notification
672 * toku owner's connection token (ipvcc protocol block)
673 * cause pointer to cause code
680 uniarp_cleared(toku, cause)
682 struct t_atm_cause *cause;
684 struct ipvcc *ivp = toku;
690 * We're done with VCC
692 ivp->iv_arpconn = NULL;
695 * If IP is finished with VCC, then we'll free it
697 if (ivp->iv_state == IPVCC_FREE)
698 atm_free((caddr_t)ivp);