/*     
 * ip_rom.c
 *
 * x-kernel v3.3
 *
 * Copyright (c) 1996,1993,1991,1990  Arizona Board of Regents
 *
 * $Revision: 1.3 $
 * $Date: 1996/06/14 21:28:54 $
 */

/* 
 * ROM file processing
 */

#include "xkernel.h"
#include "ip_i.h"
#include "rom.h"

#define ERROR { sprintf(errBuf,	 "IP ROM file format error in line %d", i+1); \
		xError(errBuf); }

void
ipProcessRomFile(self)
Protl self;
{
    char   str[30];
    int    i;
    IPhost iph;
    PState *pstate = (PState *)self->state;

    sprintf(str, "%s/%s", self->name, self->instName);
    for (i = 0; rom[i][0]; i++) {
	if (!strcmp(rom[i][0], str)) {
	    if (!rom[i][1] || ! rom[i][2]) {
		ERROR;
		continue;
	    }
	    if (!strncmp(rom[i][1], "gateway", 7)) {
		if (str2ipHost(&iph, rom[i][2]) == XK_FAILURE) {
		    ERROR;
		    continue;
		}
		pstate->ipSiteGateway = iph;
		xTrace1(ipp, TR_EVENTS, "loaded default GW %s from rom file",
			ipHostStr(&(pstate->ipSiteGateway)));
	    }
	}
    }
}

void
ipProcessRomFile2(self)
Protl self;
{
    char   str[30];
    int    i;
    IPhost iph, ipg, ipm;
    PState *pstate = (PState *)self->state;

    sprintf(str, "%s/%s", self->name, self->instName);
    for (i = 0; rom[i][0]; i++) {
        if (!strcmp(rom[i][0], str)) {
            if (!rom[i][1] || ! rom[i][2]) {
                ERROR;
                continue;
            }
            if (strncmp(rom[i][1], "gateway", 7)) {
                if (str2ipHost(&iph, rom[i][1]) == XK_FAILURE) {
                    ERROR;
                    continue;
                }
                if (str2ipHost(&ipg, rom[i][2]) == XK_FAILURE) {
                    ERROR;
                    continue;
                }
                netMaskFind(&ipm, &iph);

                /* find which interface reaches the gateway */
                rt_add(pstate, &iph, &ipm, &ipg, -1, RTDEFAULTTTL);
                return;
            }
        }
    }
}
