File: gaiconf

package info (click to toggle)
iproute 20100519-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,636 kB
  • ctags: 5,283
  • sloc: ansic: 36,665; sh: 2,282; makefile: 447; cpp: 341; yacc: 339; lex: 145; perl: 101
file content (134 lines) | stat: -rw-r--r-- 1,999 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh

#
# Setup address label from /etc/gai.conf
#
# Written by YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>, 2010.
#

IP=ip
DEFAULT_GAICONF=/etc/gai.conf
verbose=
debug=

function run ()
{
	if [ x"$verbose" != x"" ]; then
		echo "$@"
	fi
	if [ x"$debug" = x"" ]; then
		"$@"
	fi
}

function do_load_config ()
{
	file=$1; shift
	flush=1
	cat $file | while read command prefix label; do
		if [ x"$command" = x"#label" ]; then
			if [ ${flush} = 1 ]; then
				run ${IP} -6 addrlabel flush
				flush=0
			fi
			run ${IP} -6 addrlabel add prefix $prefix label $label
		fi
	done
}

function do_list_config ()
{
	${IP} -6 addrlabel list | while read p pfx l lbl; do
		echo label ${pfx} ${lbl}
	done
}

function help ()
{
	echo "Usage: $0 [-v] {--list | --config [ ${DEFAULT_GAICONF} ] | --default}"
	exit 1
}

TEMP=`getopt -o c::dlv -l config::,default,list,verbose -n gaiconf -- "$@"`

if [ $? != 0 ]; then
	echo "Terminating..." >&2
	exit 1
fi

TEMPFILE=`mktemp`

eval set -- "$TEMP"

while true ; do
	case "$1" in
		-c|--config)
			if [ x"$cmd" != x"" ]; then
				help
			fi
			case "$2" in
			"")	gai_conf="${DEFAULT_GAICONF}"
				shift 2
				;;
			*)	gai_conf="$2"
				shift 2
			esac
			cmd=config
			;;
		-d|--default)
			if [ x"$cmd" != x"" ]; then
				help
			fi
			gai_conf=${TEMPFILE}
			cmd=config
			;;
		-l|--list)
			if [ x"$cmd" != x"" ]; then
				help
			fi
			cmd=list
			shift
			;;
		-v)
			verbose=1
			shift
			;;
		--)
			shift;
			break
			;;
		*)
			echo "Internal error!" >&2
			exit 1
			;;
	esac
done

case "$cmd" in
	config)
		if [ x"$gai_conf" = x"${TEMPFILE}" ]; then
			sed -e 's/^[[:space:]]*//' <<END_OF_DEFAULT >${TEMPFILE}
				label ::1/128       0
				label ::/0          1
				label 2002::/16     2
				label ::/96         3
				label ::ffff:0:0/96 4
				label fec0::/10     5
				label fc00::/7      6
				label 2001:0::/32   7
END_OF_DEFAULT
		fi
		do_load_config "$gai_conf"
		;;
	list)
		do_list_config
		;;
	*)
		help
		;;
esac

rm -f "${TEMPFILE}"

exit 0