xref: /csrg-svn/sys/deprecated/netimp/if_imp.c (revision 26397)
1 /*
2  * Copyright (c) 1982 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)if_imp.c	6.9 (Berkeley) 02/23/86
7  */
8 
9 #include "imp.h"
10 #if NIMP > 0
11 /*
12  * ARPANET IMP interface driver.
13  *
14  * The IMP-host protocol is handled here, leaving
15  * hardware specifics to the lower level interface driver.
16  */
17 #include "../machine/pte.h"
18 
19 #include "param.h"
20 #include "systm.h"
21 #include "mbuf.h"
22 #include "buf.h"
23 #include "protosw.h"
24 #include "socket.h"
25 #include "vmmac.h"
26 #include "time.h"
27 #include "kernel.h"
28 #include "errno.h"
29 #include "ioctl.h"
30 
31 #include "../vax/cpu.h"
32 #include "../vax/mtpr.h"
33 #include "../vaxuba/ubareg.h"
34 #include "../vaxuba/ubavar.h"
35 
36 #include "../net/if.h"
37 #include "../net/route.h"
38 
39 #include "../net/netisr.h"
40 #include "../netinet/in.h"
41 #include "../netinet/in_systm.h"
42 #include "../netinet/in_var.h"
43 #include "../netinet/ip.h"
44 #include "../netinet/ip_var.h"
45 /* define IMPLEADERS here to get leader printing code */
46 #include "if_imp.h"
47 #include "if_imphost.h"
48 
49 /*
50  * IMP software status per interface.
51  * (partially shared with the hardware specific module)
52  *
53  * Each interface is referenced by a network interface structure,
54  * imp_if, which the routing code uses to locate the interface.
55  * This structure contains the output queue for the interface, its
56  * address, ...  IMP specific structures used in connecting the
57  * IMP software modules to the hardware specific interface routines
58  * are stored here.  The common structures are made visible to the
59  * interface driver by passing a pointer to the hardware routine
60  * at "attach" time.
61  *
62  * NOTE: imp_if and imp_cb are assumed adjacent in hardware code.
63  */
64 struct imp_softc {
65 	struct	ifnet imp_if;		/* network visible interface */
66 	struct	impcb imp_cb;		/* hooks to hardware module */
67 	u_char	imp_state;		/* current state of IMP */
68 	char	imp_dropcnt;		/* used during initialization */
69 } imp_softc[NIMP];
70 
71 struct ifqueue impintrq;
72 
73 /*
74  * Messages from IMP regarding why
75  * it's going down.
76  */
77 static char *impmessage[] = {
78 	"in 30 seconds",
79 	"for hardware PM",
80 	"to reload software",
81 	"for emergency reset"
82 };
83 
84 #define HOSTDEADTIMER	10		/* How long to wait when down */
85 
86 int	impdown(), impinit(), impioctl(), impoutput();
87 
88 /*
89  * IMP attach routine.  Called from hardware device attach routine
90  * at configuration time with a pointer to the UNIBUS device structure.
91  * Sets up local state and returns pointer to base of ifnet+impcb
92  * structures.  This is then used by the device's attach routine
93  * set up its back pointers.
94  */
95 impattach(ui, reset)
96 	struct uba_device *ui;
97 	int (*reset)();
98 {
99 	struct imp_softc *sc;
100 	register struct ifnet *ifp;
101 
102 #ifdef lint
103 	impintr();
104 #endif
105 	if (ui->ui_unit >= NIMP) {
106 		printf("imp%d: not configured\n", ui->ui_unit);
107 		return (0);
108 	}
109 	sc = &imp_softc[ui->ui_unit];
110 	ifp = &sc->imp_if;
111 	/* UNIT COULD BE AMBIGUOUS */
112 	ifp->if_unit = ui->ui_unit;
113 	ifp->if_name = "imp";
114 	ifp->if_mtu = IMPMTU - sizeof(struct imp_leader);
115 	ifp->if_reset = reset;
116 	ifp->if_init = impinit;
117 	ifp->if_ioctl = impioctl;
118 	ifp->if_output = impoutput;
119 	/* reset is handled at the hardware level */
120 	if_attach(ifp);
121 	return ((int)ifp);
122 }
123 
124 /*
125  * IMP initialization routine: call hardware module to
126  * setup UNIBUS resources, init state and get ready for
127  * NOOPs the IMP should send us, and that we want to drop.
128  */
129 impinit(unit)
130 	int unit;
131 {
132 	int s = splimp();
133 	register struct imp_softc *sc = &imp_softc[unit];
134 
135 	if (sc->imp_if.if_addrlist == 0)
136 		return;
137 	if ((*sc->imp_cb.ic_init)(unit) == 0) {
138 		sc->imp_state = IMPS_DOWN;
139 		sc->imp_if.if_flags &= ~IFF_UP;
140 		splx(s);
141 		return;
142 	}
143 	sc->imp_state = IMPS_INIT;
144 	impnoops(sc);
145 	splx(s);
146 }
147 
148 #ifdef IMPLEADERS
149 int	impprintfs = 0;
150 #endif
151 
152 /*
153  * ARPAnet 1822 input routine.
154  * Called from hardware input interrupt routine to handle 1822
155  * IMP-host messages.  Type 0 messages (non-control) are
156  * passed to higher level protocol processors on the basis
157  * of link number.  Other type messages (control) are handled here.
158  */
159 impinput(unit, m)
160 	int unit;
161 	register struct mbuf *m;
162 {
163 	register struct imp_leader *ip;
164 	register struct imp_softc *sc = &imp_softc[unit];
165 	struct ifnet *ifp;
166 	register struct host *hp;
167 	register struct ifqueue *inq;
168 	struct control_leader *cp;
169 	struct in_addr addr;
170 	struct mbuf *next;
171 	struct sockaddr_in *sin;
172 
173 	/*
174 	 * Pull the interface pointer out of the mbuf
175 	 * and save for later; adjust mbuf to look at rest of data.
176 	 */
177 	ifp = *(mtod(m, struct ifnet **));
178 	IF_ADJ(m);
179 	/* verify leader length. */
180 	if (m->m_len < sizeof(struct control_leader) &&
181 	    (m = m_pullup(m, sizeof(struct control_leader))) == 0)
182 		return;
183 	cp = mtod(m, struct control_leader *);
184 	if (cp->dl_mtype == IMPTYPE_DATA)
185 		if (m->m_len < sizeof(struct imp_leader) &&
186 		    (m = m_pullup(m, sizeof(struct imp_leader))) == 0)
187 			return;
188 	ip = mtod(m, struct imp_leader *);
189 #ifdef IMPLEADERS
190 	if (impprintfs)
191 		printleader("impinput", ip);
192 #endif
193 
194 	/* check leader type */
195 	if (ip->il_format != IMP_NFF) {
196 		sc->imp_if.if_collisions++;	/* XXX */
197 		goto drop;
198 	}
199 
200 	if (ip->il_mtype != IMPTYPE_DATA) {
201 		/* If not data packet, build IP addr from leader (BRL) */
202 		imp_leader_to_addr(&addr, ip, &sc->imp_if);
203 	}
204 	switch (ip->il_mtype) {
205 
206 	case IMPTYPE_DATA:
207 		break;
208 
209 	/*
210 	 * IMP leader error.  Reset the IMP and discard the packet.
211 	 */
212 	case IMPTYPE_BADLEADER:
213 		/*
214 		 * According to 1822 document, this message
215 		 * will be generated in response to the
216 		 * first noop sent to the IMP after
217 		 * the host resets the IMP interface.
218 		 */
219 		if (sc->imp_state != IMPS_INIT) {
220 			impmsg(sc, "leader error");
221 			hostreset(((struct in_ifaddr *)&sc->imp_if.if_addrlist)->ia_net);
222 			impnoops(sc);
223 		}
224 		goto drop;
225 
226 	/*
227 	 * IMP going down.  Print message, and if not immediate,
228 	 * set off a timer to insure things will be reset at the
229 	 * appropriate time.
230 	 */
231 	case IMPTYPE_DOWN:
232 		if (sc->imp_state < IMPS_INIT)
233 			goto drop;
234 		if ((ip->il_link & IMP_DMASK) == 0) {
235 			sc->imp_state = IMPS_GOINGDOWN;
236 			timeout(impdown, (caddr_t)sc, 30 * hz);
237 		}
238 		impmsg(sc, "going down %s",
239 			(u_int)impmessage[ip->il_link&IMP_DMASK]);
240 		goto drop;
241 
242 	/*
243 	 * A NOP usually seen during the initialization sequence.
244 	 * Compare the local address with that in the message.
245 	 * Reset the local address notion if it doesn't match.
246 	 */
247 	case IMPTYPE_NOOP:
248 		if (sc->imp_state == IMPS_DOWN) {
249 			sc->imp_state = IMPS_INIT;
250 			sc->imp_dropcnt = IMP_DROPCNT;
251 		}
252 		if (sc->imp_state == IMPS_INIT && --sc->imp_dropcnt > 0)
253 			goto drop;
254 		sin = (struct sockaddr_in *)&sc->imp_if.if_addrlist->ifa_addr;
255 		if (ip->il_imp != 0) {	/* BRL */
256 			struct in_addr leader_addr;
257 			imp_leader_to_addr(&leader_addr, ip, &sc->imp_if);
258 			if (sin->sin_addr.s_addr != leader_addr.s_addr) {
259 				impmsg(sc, "address reset to x%x (%d/%d)",
260 					htonl(leader_addr.s_addr),
261 					(u_int)ip->il_host,
262 					htons(ip->il_imp));
263 				sin->sin_addr.s_addr = leader_addr.s_addr;
264 			}
265 		}
266 		sc->imp_state = IMPS_UP;
267 		sc->imp_if.if_flags |= IFF_UP;
268 		goto drop;
269 
270 	/*
271 	 * RFNM or INCOMPLETE message, send next
272 	 * message on the q.  We could pass incomplete's
273 	 * up to the next level, but this currently isn't
274 	 * needed.
275 	 */
276 	case IMPTYPE_RFNM:
277 	case IMPTYPE_INCOMPLETE:
278 		if (hp = hostlookup(addr)) {
279 			hp->h_timer = HOSTTIMER;
280 			if (hp->h_rfnm == 0)
281 				hp->h_flags &= ~HF_INUSE;
282 			else if (next = hostdeque(hp))
283 				(void) impsnd(&sc->imp_if, next);
284 		}
285 		goto drop;
286 
287 	/*
288 	 * Host or IMP can't be reached.  Flush any packets
289 	 * awaiting transmission and release the host structure.
290 	 * Enqueue for notifying protocols at software interrupt time.
291 	 */
292 	case IMPTYPE_HOSTDEAD:
293 	case IMPTYPE_HOSTUNREACH:
294 		if (hp = hostlookup(addr)) {
295 			hp->h_flags |= (1 << (int)ip->il_mtype);
296 			hostfree(hp);
297 			hp->h_timer = HOSTDEADTIMER;
298 		}
299 		goto rawlinkin;
300 
301 	/*
302 	 * Error in data.  Clear RFNM status for this host and send
303 	 * noops to the IMP to clear the interface.
304 	 */
305 	case IMPTYPE_BADDATA:
306 		impmsg(sc, "data error");
307 		if (hp = hostlookup(addr))
308 			hp->h_rfnm = 0;
309 		impnoops(sc);
310 		goto drop;
311 
312 	/*
313 	 * Interface reset.
314 	 */
315 	case IMPTYPE_RESET:
316 		impmsg(sc, "interface reset");
317 		/* clear RFNM counts */
318 		hostreset(((struct in_ifaddr *)&sc->imp_if.if_addrlist)->ia_net);
319 		impnoops(sc);
320 		goto drop;
321 
322 	default:
323 		sc->imp_if.if_collisions++;		/* XXX */
324 		goto drop;
325 	}
326 
327 	/*
328 	 * Data for a protocol.  Dispatch to the appropriate
329 	 * protocol routine (running at software interrupt).
330 	 * If this isn't a raw interface, advance pointer
331 	 * into mbuf past leader.
332 	 */
333 	switch (ip->il_link) {
334 
335 	case IMPLINK_IP:
336 		m->m_len -= sizeof(struct imp_leader);
337 		m->m_off += sizeof(struct imp_leader);
338 		schednetisr(NETISR_IP);
339 		inq = &ipintrq;
340 		break;
341 
342 	default:
343 	rawlinkin:
344 		schednetisr(NETISR_IMP);
345 		inq = &impintrq;
346 		break;
347 	}
348 	/*
349 	 * Re-insert interface pointer in the mbuf chain
350 	 * for the next protocol up.
351 	 */
352 	m->m_off -= sizeof(struct ifnet *);
353 	m->m_len += sizeof(struct ifnet *);
354 	*(mtod(m, struct ifnet **)) = ifp;
355 	if (IF_QFULL(inq)) {
356 		IF_DROP(inq);
357 		goto drop;
358 	}
359 	IF_ENQUEUE(inq, m);
360 	return;
361 
362 drop:
363 	m_freem(m);
364 }
365 
366 /*
367  * Bring the IMP down after notification.
368  */
369 impdown(sc)
370 	struct imp_softc *sc;
371 {
372 	int s = splimp();
373 
374 	sc->imp_state = IMPS_DOWN;
375 	impmsg(sc, "marked down");
376 	hostreset(((struct in_ifaddr *)&sc->imp_if.if_addrlist)->ia_net);
377 	if_down(&sc->imp_if);
378 	splx(s);
379 }
380 
381 /*VARARGS2*/
382 impmsg(sc, fmt, a1, a2, a3)
383 	struct imp_softc *sc;
384 	char *fmt;
385 	u_int a1;
386 {
387 
388 	printf("imp%d: ", sc->imp_if.if_unit);
389 	printf(fmt, a1, a2, a3);
390 	printf("\n");
391 }
392 
393 struct sockproto impproto = { PF_IMPLINK };
394 struct sockaddr_in impdst = { AF_IMPLINK };
395 struct sockaddr_in impsrc = { AF_IMPLINK };
396 
397 /*
398  * Pick up the IMP "error" messages enqueued earlier,
399  * passing these up to the higher level protocol
400  * and the raw interface.
401  */
402 impintr()
403 {
404 	register struct mbuf *m;
405 	register struct control_leader *cp;
406 	struct ifnet *ifp;
407 	int s;
408 
409 	for (;;) {
410 		s = splimp();
411 		IF_DEQUEUEIF(&impintrq, m, ifp);
412 		splx(s);
413 		if (m == 0)
414 			return;
415 
416 		cp = mtod(m, struct control_leader *);
417 		imp_leader_to_addr(&impsrc.sin_addr, (struct imp_leader *)cp,
418 		    ifp);
419 		impproto.sp_protocol = cp->dl_link;
420 		impdst.sin_addr = IA_SIN(ifp->if_addrlist)->sin_addr;
421 
422 		switch (cp->dl_link) {
423 
424 		case IMPLINK_IP:
425 			pfctlinput((int)cp->dl_mtype,
426 			    (struct sockaddr *)&impsrc);
427 			break;
428 		default:
429 			raw_ctlinput((int)cp->dl_mtype,
430 			    (struct sockaddr *)&impsrc);
431 			break;
432 		}
433 
434 		raw_input(m, &impproto, (struct sockaddr *)&impsrc,
435 		  (struct sockaddr *)&impdst);
436 	}
437 }
438 
439 /*
440  * ARPAnet 1822 output routine.
441  * Called from higher level protocol routines to set up messages for
442  * transmission to the imp.  Sets up the header and calls impsnd to
443  * enqueue the message for this IMP's hardware driver.
444  */
445 impoutput(ifp, m0, dst)
446 	register struct ifnet *ifp;
447 	struct mbuf *m0;
448 	struct sockaddr *dst;
449 {
450 	register struct imp_leader *imp;
451 	register struct mbuf *m = m0;
452 	int dlink, len;
453 	int error = 0;
454 
455 	/*
456 	 * Don't even try if the IMP is unavailable.
457 	 */
458 	if (imp_softc[ifp->if_unit].imp_state != IMPS_UP) {
459 		error = ENETDOWN;
460 		goto drop;
461 	}
462 
463 	switch (dst->sa_family) {
464 
465 	case AF_INET: {
466 		struct ip *ip = mtod(m, struct ip *);
467 
468 		dlink = IMPLINK_IP;
469 		len = ntohs((u_short)ip->ip_len);
470 		break;
471 	}
472 
473 	case AF_IMPLINK:
474 		len = 0;
475 		do
476 			len += m->m_len;
477 		while (m = m->m_next);
478 		m = m0;
479 		goto leaderexists;
480 
481 	default:
482 		printf("imp%d: can't handle af%d\n", ifp->if_unit,
483 			dst->sa_family);
484 		error = EAFNOSUPPORT;
485 		goto drop;
486 	}
487 
488 	/*
489 	 * Add IMP leader.  If there's not enough space in the
490 	 * first mbuf, allocate another.  If that should fail, we
491 	 * drop this sucker.
492 	 */
493 	if (m->m_off > MMAXOFF ||
494 	    MMINOFF + sizeof(struct imp_leader) > m->m_off) {
495 		m = m_get(M_DONTWAIT, MT_HEADER);
496 		if (m == 0) {
497 			error = ENOBUFS;
498 			goto drop;
499 		}
500 		m->m_next = m0;
501 		m->m_len = sizeof(struct imp_leader);
502 	} else {
503 		m->m_off -= sizeof(struct imp_leader);
504 		m->m_len += sizeof(struct imp_leader);
505 	}
506 	imp = mtod(m, struct imp_leader *);
507 	imp->il_format = IMP_NFF;
508 	imp->il_mtype = IMPTYPE_DATA;
509 	imp_addr_to_leader(imp,
510 		((struct sockaddr_in *)dst)->sin_addr.s_addr); /* BRL */
511 	imp->il_length = htons((u_short)len << 3);		/* BRL */
512 	imp->il_link = dlink;
513 	imp->il_flags = imp->il_htype = imp->il_subtype = 0;
514 
515 leaderexists:
516 	return (impsnd(ifp, m));
517 drop:
518 	m_freem(m0);
519 	return (error);
520 }
521 
522 /*
523  * Put a message on an interface's output queue.
524  * Perform RFNM counting: no more than 8 message may be
525  * in flight to any one host.
526  */
527 impsnd(ifp, m)
528 	struct ifnet *ifp;
529 	struct mbuf *m;
530 {
531 	register struct imp_leader *ip;
532 	register struct host *hp;
533 	struct impcb *icp;
534 	int s, error;
535 
536 	ip = mtod(m, struct imp_leader *);
537 
538 	/*
539 	 * Do RFNM counting for data messages
540 	 * (no more than 8 outstanding to any host)
541 	 */
542 	s = splimp();
543 	if (ip->il_mtype == IMPTYPE_DATA) {
544 		struct in_addr addr;
545 
546 		imp_leader_to_addr(&addr, ip, ifp);	/* BRL */
547 		if ((hp = hostlookup(addr)) == 0)
548 			hp = hostenter(addr);
549 		if (hp && (hp->h_flags & (HF_DEAD|HF_UNREACH))) {
550 			error = hp->h_flags&HF_DEAD ? EHOSTDOWN : EHOSTUNREACH;
551 			hp->h_flags &= ~HF_INUSE;
552 			goto bad;
553 		}
554 
555 		/*
556 		 * If IMP would block, queue until RFNM
557 		 */
558 		if (hp) {
559 #ifndef NORFNM
560 			if (hp->h_rfnm < 8)
561 #endif
562 			{
563 				hp->h_timer = HOSTTIMER;
564 				hp->h_rfnm++;
565 				goto enque;
566 			}
567 			if (hp->h_qcnt < 8) {	/* high water mark */
568 				HOST_ENQUE(hp, m);
569 				goto start;
570 			}
571 		}
572 		error = ENOBUFS;
573 		goto bad;
574 	}
575 enque:
576 	if (IF_QFULL(&ifp->if_snd)) {
577 		IF_DROP(&ifp->if_snd);
578 		error = ENOBUFS;
579 		if (ip->il_mtype == IMPTYPE_DATA)
580 			hp->h_rfnm--;
581 bad:
582 		m_freem(m);
583 		splx(s);
584 		return (error);
585 	}
586 	IF_ENQUEUE(&ifp->if_snd, m);
587 start:
588 	icp = &imp_softc[ifp->if_unit].imp_cb;
589 	if (icp->ic_oactive == 0)
590 		(*icp->ic_start)(ifp->if_unit);
591 	splx(s);
592 	return (0);
593 }
594 
595 /*
596  * Put three 1822 NOOPs at the head of the output queue.
597  * Part of host-IMP initialization procedure.
598  * (Should return success/failure, but noone knows
599  * what to do with this, so why bother?)
600  * This routine is always called at splimp, so we don't
601  * protect the call to IF_PREPEND.
602  */
603 impnoops(sc)
604 	register struct imp_softc *sc;
605 {
606 	register i;
607 	register struct mbuf *m;
608 	register struct control_leader *cp;
609 
610 	sc->imp_dropcnt = IMP_DROPCNT;
611 	for (i = 0; i < IMP_DROPCNT + 1; i++) {
612 		if ((m = m_getclr(M_DONTWAIT, MT_HEADER)) == 0)
613 			return;
614 		m->m_len = sizeof(struct control_leader);
615 		cp = mtod(m, struct control_leader *);
616 		cp->dl_format = IMP_NFF;
617                 cp->dl_link = i;
618                 cp->dl_mtype = IMPTYPE_NOOP;
619 		IF_PREPEND(&sc->imp_if.if_snd, m);
620 	}
621 	if (sc->imp_cb.ic_oactive == 0)
622 		(*sc->imp_cb.ic_start)(sc->imp_if.if_unit);
623 }
624 
625 /*
626  * Process an ioctl request.
627  */
628 impioctl(ifp, cmd, data)
629 	register struct ifnet *ifp;
630 	int cmd;
631 	caddr_t data;
632 {
633 	struct ifaddr *ifa = (struct ifaddr *) data;
634 	int s = splimp(), error = 0;
635 
636 	switch (cmd) {
637 
638 	case SIOCSIFADDR:
639 		if (ifa->ifa_addr.sa_family != AF_INET) {
640 			error = EINVAL;
641 			break;
642 		}
643 		if ((ifp->if_flags & IFF_RUNNING) == 0)
644 			impinit(ifp->if_unit);
645 		break;
646 
647 	default:
648 		error = EINVAL;
649 	}
650 	splx(s);
651 	return (error);
652 }
653 
654 #ifdef IMPLEADERS
655 printleader(routine, ip)
656 	char *routine;
657 	register struct imp_leader *ip;
658 {
659 	printf("%s: ", routine);
660 	printbyte((char *)ip, 12);
661 	printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network,
662 		ip->il_flags);
663 	if (ip->il_mtype <= IMPTYPE_READY)
664 		printf("%s,", impleaders[ip->il_mtype]);
665 	else
666 		printf("%x,", ip->il_mtype);
667 	printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host,
668 		ntohs(ip->il_imp));
669 	if (ip->il_link == IMPLINK_IP)
670 		printf("ip,");
671 	else
672 		printf("%x,", ip->il_link);
673 	printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3);
674 }
675 
676 printbyte(cp, n)
677 	register char *cp;
678 	int n;
679 {
680 	register i, j, c;
681 
682 	for (i=0; i<n; i++) {
683 		c = *cp++;
684 		for (j=0; j<2; j++)
685 			putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf], 0);
686 		putchar(' ', 0);
687 	}
688 	putchar('\n', 0);
689 }
690 #endif
691 
692 /*
693  * Routine to convert from IMP Leader to InterNet Address.
694  *
695  * This procedure is necessary because IMPs may be assigned Class A, B, or C
696  * network numbers, but only have 8 bits in the leader to reflect the
697  * IMP "network number".  The strategy is to take the network number from
698  * the ifnet structure, and blend in the host-on-imp and imp-on-net numbers
699  * from the leader.
700  *
701  * There is no support for "Logical Hosts".
702  *
703  * Class A:	Net.Host.0.Imp
704  * Class B:	Net.net.Host.Imp
705  * Class C:	Net.net.net.(Host4|Imp4)
706  */
707 imp_leader_to_addr(ap, ip, ifp)
708 	struct in_addr *ap;
709 	register struct imp_leader *ip;
710 	struct ifnet *ifp;
711 {
712 	register u_long final;
713 	register struct sockaddr_in *sin;
714 	int imp = htons(ip->il_imp);
715 
716 	sin = (struct sockaddr_in *)(&ifp->if_addrlist->ifa_addr);
717 	final = htonl(sin->sin_addr.s_addr);
718 
719 	if (IN_CLASSA(final)) {
720 		final &= IN_CLASSA_NET;
721 		final |= (imp & 0xFF) | ((ip->il_host & 0xFF)<<16);
722 	} else if (IN_CLASSB(final)) {
723 		final &= IN_CLASSB_NET;
724 		final |= (imp & 0xFF) | ((ip->il_host & 0xFF)<<8);
725 	} else {
726 		final &= IN_CLASSC_NET;
727 		final |= (imp & 0x0F) | ((ip->il_host & 0x0F)<<4);
728 	}
729 	ap->s_addr = htonl(final);
730 }
731 
732 /*
733  * Function to take InterNet address and fill in IMP leader fields.
734  */
735 imp_addr_to_leader(imp, a)
736 	register struct imp_leader *imp;
737 	u_long a;
738 {
739 	register u_long addr = htonl(a);
740 
741 	imp->il_network = 0;	/* !! */
742 
743 	if (IN_CLASSA(addr)) {
744 		imp->il_host = ((addr>>16) & 0xFF);
745 		imp->il_imp = addr & 0xFF;
746 	} else if (IN_CLASSB(addr)) {
747 		imp->il_host = ((addr>>8) & 0xFF);
748 		imp->il_imp = addr & 0xFF;
749 	} else {
750 		imp->il_host = ((addr>>4) & 0xF);
751 		imp->il_imp = addr & 0xF;
752 	}
753 	imp->il_imp = htons(imp->il_imp);
754 }
755 #endif
756