/* dhcpcBoot.c - DHCP client finite state machine definition (boot time) */
/* Copyright 1984 - 2002 Wind River Systems, Inc. */
#include "copyright_wrs.h"
/*
modification history
--------------------
01m,25apr02,wap transmit DHCPDECLINEs as broadcasts, not unicasts (SPR
#75119)
01l,23apr02,wap use dhcpTime() instead of time() (SPR #68900) and initialize
dhcpcBootStates correctly (SPR #75042)
01k,12oct01,rae merge from truestack ver 01q, base 01g
SPRs 65264, 70116, 27426, 69731
01j,26oct00,spm fixed byte order of transaction identifier; removed reset code
01i,26oct00,spm fixed modification history after tor3_x merge
01h,23oct00,niq merged from version 01j of tor3_x branch (base version 01f)
01g,04dec97,spm added code review modifications
01f,06oct97,spm removed reference to deleted endDriver global; replaced with
support for dynamic driver type detection
01e,02sep97,spm removed name conflicts with runtime DHCP client (SPR #9241)
01d,26aug97,spm major overhaul: included version 01h of dhcpcState1.c and
version 01i of dhcpc_subr.c to retain single-lease library
for boot time use
01c,06aug97,spm removed parameters linked list to reduce memory required
01b,07apr97,spm rewrote documentation
01a,29jan97,spm created by modifying dhcpc.c module
*/
/*
DESCRIPTION
This library contains the boot-time DHCP client implementation. The library
contains routines to obtain a set of boot parameters using DHCP. Because the
bootstrap loader handles all the system configuration, the boot-time client
will not apply any configuration parameters received to the underlying network
interface.
INTERNAL
This module contains a modified version of the DHCP client finite state
machine which eliminates all states from BOUND onwards. Provided that the
obtained lease exceeds the download time for the runtime image, these routines
are not needed by the ROM-resident bootstrap loader. Their removal reduces the
size of the boot ROM image so that the DHCP client can be used with targets
like the MV147 which have limited ROM capacity. The code size is further
reduced by eliminating the routines which change the network interface settings
and maintain the correct routing table entries. Although necessary to prevent
access to an unconfigured interface during runtime, it is overkill at boot
time, since the system will not start if an error occurs. Finally, the runtime
DHCP client supports the retrieval and maintenance of multiple leases and
allows users to renew or release the corresponding parameters. Those
capabilities are not necessary at boot time.
INCLUDE_FILES: dhcpcBootLib.h
*/
/*
* WIDE Project DHCP Implementation
* Copyright (c) 1995 Akihiro Tominaga
* Copyright (c) 1995 WIDE Project
* All rights reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided only with the following
* conditions are satisfied:
*
* 1. Both the copyright notice and this permission notice appear in
* all copies of the software, derivative works or modified versions,
* and any portions thereof, and that both notices appear in
* supporting documentation.
* 2. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by WIDE Project and
* its contributors.
* 3. Neither the name of WIDE Project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND WIDE
* PROJECT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
* WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ALSO, THERE
* IS NO WARRANTY IMPLIED OR OTHERWISE, NOR IS SUPPORT PROVIDED.
*
* Feedback of the results generated from any improvements or
* extensions made to this software would be much appreciated.
* Any such feedback should be sent to:
*
* Akihiro Tominaga
* WIDE Project
* Keio University, Endo 5322, Kanagawa, Japan
* (E-mail: dhcp-dist@wide.ad.jp)
*
* WIDE project has the rights to redistribute these changes.
*/
/* includes */
#include "vxWorks.h"
#include "vxLib.h" /* checksum() declaration. */
#include "netLib.h"
#include "inetLib.h"
#include "taskLib.h"
#include "sysLib.h"
#include "ioLib.h"
#include "sockLib.h"
#include "wdLib.h"
#include "rngLib.h"
#include "logLib.h"
#include "muxLib.h"
#include "stdio.h"
#include "stdlib.h"
#include "sys/ioctl.h"
#include "time.h"
#include "netinet/in.h"
#include "netinet/ip.h"
#include "netinet/udp.h"
#include "dhcpcBootLib.h"
#include "dhcp/dhcpcCommonLib.h"
#include "bpfDrv.h"
/* defines */
#define MAX_BOOT_STATES (INFORMING + 1) /* Function pointers for all states. */
#define SLEEP_RANDOM(timer) ( (timer - 1) + (rand () % 2) )
#define REQUEST_RETRANS 4 /* Number of retries, maximum of 5. (RFC 1541). */
/* Berkeley Packet Filter instructions for catching ARP messages. */
LOCAL struct bpf_insn arpfilter[] = {
BPF_STMT(BPF_LD+BPF_TYPE, 0), /* Save lltype in accumulator */
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_ARP, 0, 9), /* ARP in frame? */
/*
* The remaining statements use the (new) BPF_HLEN alias to avoid
* any link-layer dependencies.
*/
BPF_STMT(BPF_LD+BPF_H+BPF_ABS+BPF_HLEN, 6), /* A <- ARP OP field */
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ARPOP_REPLY, 0, 7), /* ARP reply ? */
BPF_STMT(BPF_LDX+BPF_HLEN, 0), /* X <- frame data offset */
BPF_STMT(BPF_LD+BPF_B+BPF_IND, 4), /* A <- hardware size */
BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A <- sum of variable offsets */
BPF_STMT(BPF_MISC+BPF_TAX, 0), /* X <- sum of variable offsets */
BPF_STMT(BPF_LD+BPF_W+BPF_IND, 8), /* A <- sender IP address */
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, -1, 0, 1), /* -1 replaced with real IP */
BPF_STMT(BPF_RET+BPF_K, -1), /* copy entire frame */
BPF_STMT(BPF_RET+BPF_K, 0) /* unrecognized message: ignore frame */
};
LOCAL struct bpf_program arpread = {
sizeof (arpfilter) / sizeof (struct bpf_insn),
arpfilter
};
LOCAL int bpfArpDev; /* Gets any replies to ARP probes. */
LOCAL u_short dhcps_port; /* Server port, in network byte order. */
LOCAL u_short dhcpc_port; /* Client port, in network byte order. */
IMPORT struct bpf_insn dhcpfilter[]; /* For updating xid test */
IMPORT struct bpf_program dhcpread;
/* globals */
struct dhcp_param * dhcpcBootParam = NULL; /* Configuration parameters */
IMPORT LEASE_DATA dhcpcBootLeaseData;
IMPORT int dhcpcBindType; /* DHCP or BOOTP reply selected? */
/* locals */
LOCAL BOOL dhcpcOldFlag; /* Use old (padded) messages? */
LOCAL int dhcpcCurrState; /* Current state */
LOCAL int dhcpcPrevState; /* Previous state */
LOCAL int dhcpcMsgLength; /* Current message size. */
LOCAL struct if_info dhcpcIntface; /* Network interface */
LOCAL struct buffer sbuf; /* Buffer for outgoing messages */
LOCAL struct msg dhcpcMsgIn; /* Incoming message components */
LOCAL struct msg dhcpcMsgOut; /* Outgoing message components */
LOCAL unsigned char dhcpCookie [MAGIC_LEN] = RFC1048_MAGIC;
LOCAL struct ps_udph spudph;
LOCAL int (*dhcpcBootStates [MAX_BOOT_STATES]) ();
LOCAL int handle_ip();
LOCAL int handle_num();
LOCAL int handle_ips();
LOCAL int handle_str();
LOCAL int handle_bool();
LOCAL int handle_ippairs();
LOCAL int handle_nums();
LOCAL int handle_list();
LOCAL int (*handle_param [MAXTAGNUM]) () =
{
NULL, /* PAD */
handle_ip, /* SUBNET_MASK */
handle_num, /* TIME_OFFSET */
handle_ips, /* ROUTER */
handle_ips, /* TIME_SERVER */
handle_ips, /* NAME_SERVER */
handle_ips, /* DNS_SERVER */
handle_ip
评论0