[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: RFC: new network config (was: Re: network configuration)



In article <cistron.19990206094148.P12960@taz.net.au>,
Craig Sanders  <cas@taz.net.au> wrote:
>On Fri, Feb 05, 1999 at 11:28:44PM +0100, Miquel van Smoorenburg wrote:
>> > > Config files with fixed fields are evil. Really evil.
>> > 
>did you see the second colon-delimited format i suggested?
>
>three fixed fields (ip, domain, username) followed by a comma-delimited
>"flags" field.

Craig, I just wated to say that it's usually better to do the right
thing straight from the start. But it's easy for me to speak since I
am not the one who has to implement it.

I do have a lot of experience with shell scripting, and it'd be easy
for me to write a simple shell script that can parse the formats I
proposed without any external tools.

If you are interested in this I'd be happy to help out with the scripts.
If you decide to go with the format you proposed, that's also fine
with me.

One other thing that migh be important. Check out how RedHat does it-
if we're going to redesign the network setup we might want to be
compatible with them

Hmm, that's probably the most sensible thing to do.

Oh well I wrote a sample shell script and still would like to show
off with it so I'm including it anyway :)

This input: (file "foo"):

# First interface
interface eth0 {
	ip = 192.168.1.1
	mask = 255.255.255.0
	broadcast = 192.168.1.255
}

# Second interface
interface eth1 {
	ip = 192.168.2.1
	mask = 255.255.255.0
	broadcast = 192.168.2.255
}

Produces the following output:

Configuring interface eth0
IP    192.168.1.1
MASK  255.255.255.0
BCAST 192.168.1.255

Configuring interface eth1
IP    192.168.2.1
MASK  255.255.255.0
BCAST 192.168.2.255

And this is the script itself:


#! /bin/sh

#
#	Read config file.
#
readconf() {

	# Open config file.
	if  [ ! -f "$1" ]
	then
		echo "readconf: $1: cannot open" >&2
		return 1
	fi
	exec 10>&0 < $1

	# Read config file.
	while read keyword name brace
	do
		if [ "$keyword" = "interface" -a "$brace" = "{" ]
		then
			readifdata
			setupif
		fi
	done

	# Close file.
	exec 0>&10 10>&-

	return 0
}

#
#	Read interface data.
#
readifdata()
{
	# Reset all vars
	ip=
	mask=
	broadcast=

	while read var equal val
	do
		case "$var" in
			""|\#*)
				continue
				;;
			\})
				break
				;;
		esac
		eval "$var=$val"
	done
}

#
#	Set up interface
#
setupif() {
	echo "Configuring interface $name"
	echo "IP    $ip"
	echo "MASK  $mask"
	echo "BCAST $broadcast"
	echo
}


readconf foo




Mike.
-- 
Indifference will certainly be the downfall of mankind, but who cares?


Reply to: