| package/base-files/files/lib/network/config.sh |
| 164 | 164 | local macaddr |
| 165 | 165 | config_get macaddr "$config" macaddr |
| 166 | 166 | [ -x /usr/sbin/brctl ] && { |
| 167 | # Remove IPv6 link local addr before adding the iface to the bridge |
| 168 | local llv6="$(ifconfig "$iface")" |
| 169 | case "$llv6" in |
| 170 | *fe80:*/64*) |
| 171 | llv6="${llv6#* fe80:}" |
| 172 | ifconfig "$iface" del "fe80:${llv6%% *}" |
| 173 | ;; |
| 174 | esac |
| 175 | |
| 167 | 176 | ifconfig "br-$config" 2>/dev/null >/dev/null && { |
| 168 | 177 | local newdevs devices |
| 169 | 178 | config_get devices "$config" device |
| ... | ... | |
| 246 | 255 | config_get cfg "$config" interface |
| 247 | 256 | [ "$parent" == "$cfg" ] || return 0 |
| 248 | 257 | |
| 258 | # parent device and ifname |
| 259 | local p_device p_type |
| 260 | config_get p_device "$cfg" device |
| 261 | config_get p_type "$cfg" type |
| 262 | |
| 263 | # select alias ifname |
| 264 | local layer use_iface |
| 265 | config_get layer "$config" layer 2 |
| 266 | case "$layer:$p_type" in |
| 267 | # layer 3: e.g. pppoe-wan or pptp-vpn |
| 268 | 3:*) use_iface="$iface" ;; |
| 269 | |
| 270 | # layer 2 and parent is bridge: e.g. br-wan |
| 271 | 2:bridge) use_iface="br-$cfg" ;; |
| 272 | |
| 273 | # layer 1: e.g. eth0 or ath0 |
| 274 | *) use_iface="$p_device" ;; |
| 275 | esac |
| 276 | |
| 249 | 277 | # alias counter |
| 250 | 278 | local ctr |
| 251 | 279 | config_get ctr "$parent" alias_count 0 |
| ... | ... | |
| 258 | 286 | append list "$config" |
| 259 | 287 | config_set "$parent" aliases "$list" |
| 260 | 288 | |
| 261 | | iface="$iface:$ctr" |
| 262 | | set_interface_ifname "$config" "$iface" |
| 289 | use_iface="$use_iface:$ctr" |
| 290 | set_interface_ifname "$config" "$use_iface" |
| 263 | 291 | |
| 264 | 292 | local proto |
| 265 | 293 | config_get proto "$config" proto "static" |
| 266 | 294 | case "${proto}" in |
| 267 | 295 | static) |
| 268 | | setup_interface_static "$iface" "$config" |
| 296 | setup_interface_static "$use_iface" "$config" |
| 269 | 297 | ;; |
| 270 | 298 | *) |
| 271 | 299 | echo "Unsupported type '$proto' for alias config '$config'" |
| ... | ... | |
| 275 | 303 | } |
| 276 | 304 | |
| 277 | 305 | setup_interface() { |
| 278 | | local iface_main="$1" |
| 306 | local iface="$1" |
| 279 | 307 | local config="$2" |
| 280 | 308 | local proto="$3" |
| 281 | 309 | local vifmac="$4" |
| 282 | | local ip6addr_main= |
| 283 | 310 | |
| 284 | 311 | [ -n "$config" ] || { |
| 285 | | config=$(find_config "$iface_main") |
| 312 | config=$(find_config "$iface") |
| 286 | 313 | [ "$?" = 0 ] || return 1 |
| 287 | 314 | } |
| 288 | 315 | |
| 289 | | prepare_interface "$iface_main" "$config" "$vifmac" || return 0 |
| 316 | prepare_interface "$iface" "$config" "$vifmac" || return 0 |
| 290 | 317 | |
| 291 | | [ "$iface_main" = "br-$config" ] && { |
| 318 | [ "$iface" = "br-$config" ] && { |
| 292 | 319 | # need to bring up the bridge and wait a second for |
| 293 | 320 | # it to switch to the 'forwarding' state, otherwise |
| 294 | 321 | # it will lose its routes... |
| 295 | | ifconfig "$iface_main" up |
| 322 | ifconfig "$iface" up |
| 296 | 323 | sleep 1 |
| 297 | 324 | } |
| 298 | 325 | |
| 299 | 326 | # Interface settings |
| 300 | | grep "$iface_main:" /proc/net/dev > /dev/null && { |
| 327 | grep "$iface:" /proc/net/dev > /dev/null && { |
| 301 | 328 | local mtu macaddr |
| 302 | 329 | config_get mtu "$config" mtu |
| 303 | 330 | config_get macaddr "$config" macaddr |
| 304 | | [ -n "$macaddr" ] && $DEBUG ifconfig "$iface_main" down |
| 305 | | $DEBUG ifconfig "$iface_main" ${macaddr:+hw ether "$macaddr"} ${mtu:+mtu $mtu} up |
| 331 | [ -n "$macaddr" ] && $DEBUG ifconfig "$iface" down |
| 332 | $DEBUG ifconfig "$iface" ${macaddr:+hw ether "$macaddr"} ${mtu:+mtu $mtu} up |
| 306 | 333 | } |
| 307 | | set_interface_ifname "$config" "$iface_main" |
| 334 | set_interface_ifname "$config" "$iface" |
| 308 | 335 | |
| 309 | 336 | [ -n "$proto" ] || config_get proto "$config" proto |
| 310 | 337 | case "$proto" in |
| 311 | 338 | static) |
| 312 | | config_get ip6addr_main "$config" ip6addr |
| 313 | | setup_interface_static "$iface_main" "$config" |
| 339 | setup_interface_static "$iface" "$config" |
| 314 | 340 | ;; |
| 315 | 341 | dhcp) |
| 316 | | local lockfile="/var/lock/dhcp-$iface_main" |
| 342 | local lockfile="/var/lock/dhcp-$iface" |
| 317 | 343 | lock "$lockfile" |
| 318 | 344 | |
| 319 | 345 | # prevent udhcpc from starting more than once |
| 320 | | local pidfile="/var/run/dhcp-${iface_main}.pid" |
| 346 | local pidfile="/var/run/dhcp-${iface}.pid" |
| 321 | 347 | local pid="$(cat "$pidfile" 2>/dev/null)" |
| 322 | 348 | if [ -d "/proc/$pid" ] && grep -qs udhcpc "/proc/${pid}/cmdline"; then |
| 323 | 349 | lock -u "$lockfile" |
| 324 | 350 | else |
| 325 | | local ipaddr netmask hostname proto1 clientid |
| 351 | local ipaddr netmask hostname proto1 clientid broadcast |
| 326 | 352 | config_get ipaddr "$config" ipaddr |
| 327 | 353 | config_get netmask "$config" netmask |
| 328 | 354 | config_get hostname "$config" hostname |
| 329 | 355 | config_get proto1 "$config" proto |
| 330 | 356 | config_get clientid "$config" clientid |
| 357 | config_get_bool broadcast "$config" broadcast 0 |
| 331 | 358 | |
| 332 | 359 | [ -z "$ipaddr" ] || \ |
| 333 | | $DEBUG ifconfig "$iface_main" "$ipaddr" ${netmask:+netmask "$netmask"} |
| 360 | $DEBUG ifconfig "$iface" "$ipaddr" ${netmask:+netmask "$netmask"} |
| 334 | 361 | |
| 335 | 362 | # don't stay running in background if dhcp is not the main proto on the interface (e.g. when using pptp) |
| 336 | 363 | local dhcpopts |
| 337 | 364 | [ ."$proto1" != ."$proto" ] && dhcpopts="-n -q" |
| 338 | | $DEBUG eval udhcpc -t 0 -i "$iface_main" ${ipaddr:+-r $ipaddr} ${hostname:+-H $hostname} ${clientid:+-c $clientid} -b -p "$pidfile" ${dhcpopts:- -O rootpath -R &} |
| 365 | [ "$broadcast" = 1 ] && broadcast="-O broadcast" || broadcast= |
| 366 | |
| 367 | $DEBUG eval udhcpc -t 0 -i "$iface" \ |
| 368 | ${ipaddr:+-r $ipaddr} \ |
| 369 | ${hostname:+-H $hostname} \ |
| 370 | ${clientid:+-c $clientid} \ |
| 371 | -b -p "$pidfile" $broadcast \ |
| 372 | ${dhcpopts:- -O rootpath -R &} |
| 373 | |
| 339 | 374 | lock -u "$lockfile" |
| 340 | 375 | fi |
| 341 | 376 | ;; |
| 342 | 377 | none) |
| 343 | | setup_interface_none "$iface_main" "$config" |
| 378 | setup_interface_none "$iface" "$config" |
| 344 | 379 | ;; |
| 345 | 380 | *) |
| 346 | 381 | if ( eval "type setup_interface_$proto" ) >/dev/null 2>/dev/null; then |
| 347 | | eval "setup_interface_$proto '$iface_main' '$config' '$proto'" |
| 382 | eval "setup_interface_$proto '$iface' '$config' '$proto'" |
| 348 | 383 | else |
| 349 | 384 | echo "Interface type $proto not supported." |
| 350 | 385 | return 1 |
| 351 | 386 | fi |
| 352 | 387 | ;; |
| 353 | 388 | esac |
| 354 | | [ "$proto" = none ] || { |
| 355 | | for ifn in `ifconfig | grep "^$iface_main:" | awk '{print $1}'`; do |
| 356 | | ifconfig "$ifn" down |
| 357 | | done |
| 358 | | } |
| 359 | | |
| 360 | | local aliases |
| 361 | | config_set "$config" aliases "" |
| 362 | | config_set "$config" alias_count 0 |
| 363 | | config_foreach setup_interface_alias alias "$config" "$iface_main" |
| 364 | | config_get aliases "$config" aliases |
| 365 | | [ -z "$aliases" ] || uci_set_state network "$config" aliases "$aliases" |
| 366 | | |
| 367 | | # put the ip6addr back to the beginning to become the main ip again |
| 368 | | [ -z "$ip6addr_main" ] || { |
| 369 | | $DEBUG ifconfig "$iface_main" del "$ip6addr_main" |
| 370 | | $DEBUG ifconfig "$iface_main" add "$ip6addr_main" |
| 371 | | } |
| 372 | 389 | } |
| 373 | 390 | |
| 374 | 391 | stop_interface_dhcp() { |