Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.14 KB | None | 0 0
  1. #!/bin/bash
  2. # Network Interface Configuration System
  3. # Copyright (c) 1996-2009 Red Hat, Inc. all rights reserved.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License, version 2,
  7. # as published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17.  
  18. unset WINDOW # defined by screen, conflicts with our usage
  19.  
  20. . /etc/init.d/functions
  21.  
  22. cd /etc/sysconfig/network-scripts
  23. . ./network-functions
  24.  
  25. [ -f ../network ] && . ../network
  26.  
  27. CONFIG=${1}
  28.  
  29. [ -z "${CONFIG}" ] && {
  30.     echo $"Usage: ifup <configuration>" >&2
  31.     exit 1
  32. }
  33.  
  34. need_config "${CONFIG}"
  35.  
  36. [ -f "${CONFIG}" ] || {
  37.     echo $"$0: configuration for ${1} not found." >&2
  38.     echo $"Usage: ifup <configuration>" >&2
  39.     exit 1
  40. }
  41.  
  42. if [ ${UID} != 0 ]; then
  43.     if [ -x /usr/sbin/usernetctl ]; then
  44.         source_config
  45.         if /usr/sbin/usernetctl ${CONFIG} report ; then
  46.             exec /usr/sbin/usernetctl ${CONFIG} up
  47.         fi
  48.     fi
  49.     echo $"Users cannot control this device." >&2
  50.     exit 1
  51. fi
  52.  
  53. source_config
  54.  
  55. if [ "foo$2" = "fooboot" ] && [ "${ONBOOT}" = "no" -o "${ONBOOT}" = "NO" ]
  56. then
  57.     exit 0
  58. fi
  59. if [ -n "$IN_HOTPLUG" ] && [ "${HOTPLUG}" = "no" -o "${HOTPLUG}" = "NO" ]
  60. then
  61.     exit 0
  62. fi
  63. if [ -n "$IN_HOTPLUG" -a "${TYPE}" = "Bridge" ];
  64. then
  65.     exit 0
  66. fi
  67.  
  68. if [ "$_use_nm" = "true" -a -n "$UUID" -a "$REALDEVICE" != "lo" ]; then
  69.     if [ "foo$2" = "fooboot" ] && [ "${TYPE}" = "Wireless" ]; then
  70.         exit 0
  71.     fi
  72.     [ -n "${DEVICE}" ] && is_nm_handling ${DEVICE} && exit 0
  73.     nmcli con up uuid "$UUID"
  74.     exit $?
  75. fi
  76.  
  77. # Ethernet 802.1Q VLAN support
  78. if [ "${VLAN}" = "yes" ] && [ "$ISALIAS" = "no" ] && [ -n "$DEVICE" ]; then
  79.     if [ -n "${VID}" ]; then
  80.         if test -z "$PHYSDEV"; then
  81.             net_log $"PHYSDEV should be set for device ${DEVICE}"
  82.             exit 1
  83.         fi
  84.     else
  85.         VID=""
  86.         MATCH='^.+\.[0-9]{1,4}$'
  87.         if [[ "${DEVICE}" =~ $MATCH ]]; then
  88.             VID=$(echo "${DEVICE}" | LC_ALL=C sed 's/^.*\.\([0-9]\+\)/\1/')
  89.             PHYSDEV=${DEVICE%.*}
  90.         fi
  91.         MATCH='^vlan[0-9]{1,4}?'
  92.         if [[ "${DEVICE}" =~ $MATCH ]]; then
  93.             VID=$(echo "${DEVICE}" | LC_ALL=C sed 's/^vlan0*//')
  94.             # PHYSDEV should be set in ifcfg-vlan* file
  95.             if test -z "$PHYSDEV"; then
  96.                 net_log $"PHYSDEV should be set for device ${DEVICE}"
  97.                 exit 1
  98.                         fi
  99.         fi
  100.     fi
  101.     if [ -n "$VID" ]; then
  102.         if [ ! -d /proc/net/vlan ]; then
  103.             if ! modprobe 8021q >/dev/null 2>&1 ; then
  104.                 net_log $"No 802.1Q VLAN support available in kernel for device ${DEVICE}"
  105.                 exit 1
  106.             fi
  107.         fi
  108.  
  109.         is_available_wait ${PHYSDEV} ${DEVTIMEOUT} || {
  110.             if [ "$?" = "1" ] ; then
  111.                 net_log $"$alias device ${DEVICE} does not seem to be present, delaying initialization."
  112.                 exit 1
  113.             else
  114.                 exit 0
  115.             fi
  116.         }
  117.  
  118.         # Link on Physical device needs to be up but no ip required
  119.         check_device_down ${PHYSDEV} && { ip -o link set dev ${PHYSDEV} up; }
  120.  
  121.         if [ ! -f /proc/net/vlan/${DEVICE} ]; then
  122.             if [ "${REORDER_HDR}" = "no" -o "${REORDER_HDR}" = "0" ]; then
  123.                 FLAG_REORDER_HDR="reorder_hdr off"
  124.             fi
  125.  
  126.             if [ "${GVRP}" = "yes" -o "${GVRP}" = "1" ]; then
  127.                 FLAG_GVRP="gvrp on"
  128.             fi
  129.  
  130.             ip link add dev ${DEVICE} link ${PHYSDEV} type vlan id ${VID} ${FLAG_REORDER_HDR} ${FLAG_GVRP} || {
  131.                 (/usr/bin/logger -p daemon.info -t ifup \
  132.                      $"ERROR: could not add vlan ${VID} as ${DEVICE} on dev ${PHYSDEV}" &) &
  133.                 net_log $"ERROR: could not add vlan ${VID} as ${DEVICE} on dev ${PHYSDEV}"
  134.                 exit 1
  135.             }
  136.  
  137.             [ -n "${VLAN_EGRESS_PRIORITY_MAP}" ] && ip link set ${DEVICE} type vlan egress ${VLAN_EGRESS_PRIORITY_MAP}
  138.         fi
  139.     fi
  140.  
  141.     /usr/lib/systemd/systemd-sysctl \
  142.         --prefix "/proc/sys/net/ipv4/conf/${DEVICE}" \
  143.         --prefix "/proc/sys/net/ipv6/conf/${DEVICE}"
  144.        fi
  145.  
  146. if [ "${BOOTPROTO}" = "bootp" -o "${BOOTPROTO}" = "dhcp" ]; then
  147.     DYNCONFIG=true
  148. fi
  149.  
  150. if [ -x /sbin/ifup-pre-local ]; then
  151.     /sbin/ifup-pre-local ${CONFIG} $2
  152. fi
  153.  
  154. OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${DEVICETYPE}"
  155.  
  156. if [ ! -x ${OTHERSCRIPT} ]; then
  157.     OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${TYPE}"
  158. fi
  159.  
  160. if [ ! -x ${OTHERSCRIPT} ]; then
  161.     OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-eth"
  162. fi
  163.  
  164. exec ${OTHERSCRIPT} ${CONFIG} $2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement