lfs-uefi: fix efivar-37 FTBFS
[linux_from_scratch_hints.git] / IPv6-in-LFS.txt
blobaf3ec78e20dc9b7de89d2545b81333a100f2e67f
1 Hint to allow static IPv6 in LFS
2 Sun Dec  8 13:33:36 PST 2019
3         
4 AUTHOR: Joel Bion <jpbipv6hints at gmail.com>
6 DATE: 2019-12-08
8 LICENSE:
10 GNU Free Documentation License Version 1.2, with the additional requirement
11 that the "WARRANTY DISCLAIMER" sections are strictly adhered to by all users of
12 this document and/or its contents.
14 SYNOPSIS: Using a static IPv6 address with LFS
16 DESCRIPTION:
18 This hint describes how a static IPv6 address can be added to a system built
19 with LFS.
21 WARRANTY DISCLAIMER:
23 1. DISCLAIMER OF WARRANTY
25 THERE IS NO WARRANTY FOR THIS DOCUMENT, TO THE EXTENT PERMITTED BY APPLICABLE
26 LAW. THE COPYRIGHT HOLDER, AUTHORS, AND/OR OTHER PARTIES PROVIDE THE DOCUMENT
27 AND/OR ITS INFORMATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
28 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
30 QUALITY AND PERFORMANCE OF THE DOCUMENT AND/OR ITS INFORMATION IS WITH YOU.
31 SHOULD THE DOCUMENT AND/OR ITS INFORMATION PROVE DEFECTIVE, YOU ASSUME THE COST
32 OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
34 2. Limitation of Liability.
36 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
37 COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE DOCUMENT
38 AND/OR ITS INFORMATION AS PERMITTED IN ITS LICENSE, BE LIABLE TO YOU FOR
39 DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
40 ARISING OUT OF THE USE OR INABILITY TO USE THE DOCUMENT AND/OR ITS INFORMATION
41 (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
42 LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE DOCUMENT AND/OR
43 ITS INFORMATION TO ACHIEVE ITS INTENDED RESULT), EVEN IF SUCH HOLDER OR OTHER
44 PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 3. Interpretation of Sections 1 and 2.
48 If the disclaimer of warranty and limitation of liability provided above cannot
49 be given local legal effect according to their terms, reviewing courts shall
50 apply local law that most closely approximates an absolute waiver of all civil
51 liability in connection with the documentation and/or its contents.
53 ATTACHMENTS:
55 None
57 PREREQUISITES:
59 This hint requires you to have a working LFS system, with a static IPv4
60 address. The hint was built with LFS version 9.0, but is likely to work back to
61 version 7.0.
63 This hint requires that you have a good understanding of IPv6, including, but
64 not limited to, IPv6 address formats, the differences between things such as
65 link-local addresses vs. global addresses, what IPv6 Router Advertisements are,
66 and what they usually provide to a host, what prefix delegation is, etc.  In
67 other words, you should be fully IPv6 knowledgeable, and are just looking for
68 how to incorporate IPv6 into your LFS system.
70 Note: ISPs have not completely standardized on how they provide IPv6
71 connectivity. This hint works with ISPs that let you choose an IPv6 address
72 within the range of a prefix delegation you've been assigned, and do not filter
73 your choice of that address. Further, the default use of the system is one
74 where the default gateway is given to the system via IPv6-RD. It may also work
75 with ISPs who are similar to the above description, but require you to
76 configure a default gateway address.
78 SECURITY CONSIDERATIONS:
80 THERE ARE PLENTY OF SECURITY CONSIDERATIONS!
82 It is assumed that you have a deep understanding of the security implications
83 of adding IPv6 support to a network and/or hosts (server, client, etc.).  If
84 you do not have such an understanding, or/and have not configured and tested
85 your network and end systems to ensure they will be equally or better protected
86 with IPv6 enabled, you need to question whether or not you are properly ready,
87 from a security standpoint, to enable IPv6. Security and protection are 100%
88 your responsibility! For example, the original author of this hint does not
89 enable global IPv6 in his home network out of concern over IPv6 security.
90 You've been warned!
92 HINT:
94 Used in this hint:
96    IPv6 address: 2001:DB8:1234::123:150
97    IPv6 prefix: 112
98    IPv4 address: 192.51.100.93
99    IPv4 broadcast: 192.51.100.255
100    IPv4 prefix: 24
101    IPv4 gateway: 192.51.100.1
102    Domain name: example.com
103    Interface name: eth0
105 HINT STEP 1 - PREPARING FOR IPv6
107 How you exactly and completely do this is well beyond the scope of this hint.
108 It turns out simply enabling IPv6 is quite easy. But, preparing for it and
109 adjusting to its consequences can be difficult. This hint step describes the
110 various things you must consider before you introduce IPv6 to your system. As a
111 point of reference: the hint author spent perhaps a few hours figuring out how
112 to add IPv6 to his LFS system. But he spent multiple weekends preparing for it,
113 and the last repercussions (the creation of a PTR record by his ISP) took over
114 a week.
116 HINT STEP 1A - SECURITY
118 As said above, protecting your host and network with IPv6 enabled is different
119 than doing this in an IPv4 world. Some things are similar, but other things are
120 quite different. You cannot assume that a good knowledge of IPv4 security is
121 all you need to know to make the same network/server secure when running IPv6.
122 Study up on this, read a book or two about it, etc. Learn more than you know
123 about IPv4 security because IPv6 security is more complex, and introduces
124 concepts (such as global reach-ability of your systems) that you may never have
125 faced before. YOU are responsible for your system's security and to know the
126 risks that enabling ipv6 creates!
128 HINT STEP 1B - DNS CONSIDERATIONS
130 Depending on your needs, do you have all the proper IPv6-supporting records you
131 need in your domain's zone file? Depending on how you have previously set
132 things up, you may need to not just add a AAAA edit DMARC, MX, etc records set
133 up at your domain name provider? If you are sending email from your LFS system,
134 you may need to have a PTR record created by your ISP that provides 'reverse
135 DNS' support. This PTR record may take your ISP days or weeks to set up - so
136 plan ahead, and verify that all is set up property (even your ISP's PTR record)
137 rather than assuming it all will work!
139 HINT STEP 1C - COPING WITH IP ADDRESS OR IPv4 PROTOCOL-SPECIFIC CONFIGURATIONS
141 Most likely, you are familiar with IPv4 addresses in /etc/hosts, but a system
142 that has been using a static IPv4 address for some time may have its numeric
143 IPv4 address stored in many configurations. It may also have the network
144 portion of the IPv4 address stored in places, with the host portion of the
145 number zeroed out (for example: 192.51.100.0) or perhaps specify the broadcast
146 address explicitly (for example: 192.51.100.255.) You may also have
147 applications that need to have IPv6 support configured in, or may make new
148 decisions when they discover IPv6 is enabled that you need to configure around,
149 etc. You need to figure this out to get your system up and properly behaving
150 with both IPv4 and IPv6 configured.
152 HINT STEP 1D - OBTAINING ADDITIONAL PACKAGES REQUIRED TO SUPPORT IPv6.
154 There is the occasional package that needs to have an additional package added
155 to the system to support IPv6. This is particularly true of applications that
156 are written in languages that encourage the use of widely-available libraries
157 to perform much of the work (examples include Perl and Python.) So, for your
158 installed packages, check out which ones are directly utilizing the Internet in
159 any way, and see if they require any extra packages to support IPv6.
161 HINT STEP 1E - ENABLE IPv6 IN THE LINUX KERNEL
163 Rebuild the Linux kernel, as specified in the LFS documentation, but examine
164 your configuration file, and edit it to ensure the following lines are set.
166     CONFIG_IPV6=y
167       - Essential IPv6 support
168     CONFIG_IPV6_SIT=y
169       - Enables use of IPv6-in-IPv4 tunnels - one day you may need this
170     CONFIG_IPV6_NDISC_NODETYPE=y
171       - Enables certain checks on neighbor discovery
172     CONFIG_IPV6_TUNNEL=y
173       - Supports RFC2473 IPv6-in-IPv6 and IPv4-in-IPv6 tunnels- one day you
174         may need this
175     CONFIG_IPV6_MULTIPLE_TABLES=y
176     CONFIG_IPV6_SUBTREES=y
177       - Together, the above two enable support for multiple IPv6 routingi tables
178         (such as source-addressed based routing)
179     CONFIG_INET6_AH=y
180     CONFIG_INET6_ESP=y
181     CONFIG_INET6_IPCOMP=y
182     CONFIG_INET6_XFRM_TUNNEL=y
183     CONFIG_INET6_TUNNEL=y
184       - Above needed for IPsec with IPv6. You may not use this; the hint author
185         does.
186     CONFIG_NF_SOCKET_IPV6=m
187     CONFIG_NF_TPROXY_IPV6=m
188     CONFIG_NF_TABLES_IPV6=y
189     CONFIG_NFT_REJECT_IPV6=m
190     CONFIG_NFT_FIB_IPV6=m
191     CONFIG_NF_REJECT_IPV6=y
192     CONFIG_NF_LOG_IPV6=m
193     CONFIG_IP6_NF_MATCH_IPV6HEADER=y
194     CONFIG_NF_DEFRAG_IPV6=y
195      - Netfilter support for various commonly-referenced elements of IPv6
196        packet filtering. Many host-based firewall tools need these to be
197        enabled.
199 HINT STEP 2 - INSTALL NEW VERSIONS OF MULTIPLE LFS SCRIPTS
201 Script copies are given at the end of this hint. Put them in place in the
202 location specified, overwriting the files you have in some cases with these new
203 versions. You should save backup copies of any scripts you are about to replace
204 or modify. The modified scripts have been tested in the hint author's system to
205 still work even if IPv6 is NOT used.
207 NOTE: THESE VERSIONS OF THE SCRIPT ARE KNOWN TO WORK IN LFS 9.0, IN SYSTEMS
208 USING THE LFS-Bootscripts PACKAGE DATED 20191031. IF YOUR BOOTSCRIPTS ARE FROM
209 A DIFFERENT VERSION, YOU SHOULD CHECK TO SEE THESE STILL CAN BE USED BY CLOSELY
210 COMPARING THESE GIVEN VERSIONS TO THE ONES ON YOUR SYSTEM.  HINT STEP 3 -
211 MODIFY VARIOUS CONFIGURATION FILES
213 HINT STEP 3A - MODIFY /etc/sysconfig/ifconfig.eth0
215 In /etc/sysconfig/ifconfig.eth0, add in your IPv6 address and prefix, and
216 change the service pointer to ipv46-static, to create a resulting file that
217 looks something like this.  Obviously, edit to match your setup.
219     ONBOOT=yes
220     IFACE=eth0
221     SERVICE=ipv46-static
222     IP=192.51.100.93
223     PREFIX=24
224     GATEWAY=192.51.100.1
225     BROADCAST=192.51.100.255
226     IP6=2001:DB8:1234::123:150
227     PREFIX6=112
229 HINT STEP 3B - MODIFY /etc/hosts
231 Add the following to /etc/hosts, if not already there. Obviously, edit to match
232 your setup.
234    2001:DB8:1234::123:150 example.com
235    2001:DB8:1234::123:150 www.example.com (maybe)
236    ::1     localhost ip6-localhost ip6-loopback ourserver
237    fe00::0 ip6-localnet
238    ff00::0 ip6-mcastprefix
239    ff02::1 ip6-allnodes
240    ff02::2 ip6-allrouters
241    ff02::3 ip6-allhosts
243 HINT STEP 3C - EDIT (OR POSSIBLE EVEN CREATE) /etc/sysctl.conf
245 Add the following lines to /etc/sysctl.conf. Obviously, edit to match your
246 setup.
248        net.ipv6.conf.eth0.disable_ipv6=0
249        net.ipv6.conf.eth0.autoconf=0
251 What they do:
253        net.ipv6.conf.eth0.disable_ipv6=0
254         - 'disables the disabling' (net result, enables) IPv6 on this interface
255        net.ipv6.conf.eth0.autoconf=0
256         - Disables receiving an IPv6 address from IPv6-RD packets sent by your
257           gateway/router.
259 NOTE: If you plan to disable IPv6, you should change the sysctl.conf entries to
260 read as follows, as well as reverting your ifconfig.eth0 file.
262 Example of sysctl.conf entries to help revert from using IPv6:
264        net.ipv6.conf.eth0.disable_ipv6=1
265        net.ipv6.conf.eth0.autoconf=1
267 HINT STEP 3D (OPTIONAL) - create/edit /etc/sysconfig/network
269    Add in the line shown below. There may still be a very small number of
270    applications and/or packages that need to see this line in this file to
271    'believe' that IPv6 is enabled on your system, and it is painful to discover
272    and debug the ones that do. It's much easier to just add the following line
273    to this file, even though it's pretty frustrating and clumsy to have to do
274    this:
276      NETWORKING_IPV6=yes
278 HINT STEP 4 - Reboot and check things out
280     Upon reboot, issue these commands and see if they give sensible results:
282       ip -4 address
283       ip -4 route
284       ip -6 address
285       ip -6 route
287     The 'address' variant should show you interface addresses. Ideally, you
288     have only ONE global IPv6 address on your interface: the one you
289     configured. But you should also have link-specific addresses as well.
291     The 'route' variant should show a default gateway. If you see it, try
292     testing by using 'ping6' on a few well known sites. While this hint cannot
293     'sponsor' any by listing it, just think of the major websites in the world.
294     Some won't support IPv6, but some will, and you should see that you get
295     successful 'ping6' packets sent to one or more of these. If none work, you
296     need to examine and debug things. You may need to manually set up your IPv6
297     gateway with the GATEWAY6=<ipv6-address-of-gateway> parameter in the
298     ifconfig.<interface-name> file.
300     NOTE: YOUR MACHINE IS NOW POTENTIALLY REACHABLE ON THE GLOBAL INTERNET WITH
301     IPv6!
303 HINT STEP 5 - IF YOU HAVEN'T CONFIGURED PROPER SECURITY MEASURES FOR IPv6...
305     ...then good-golly, please do so NOW! Your system could be vulnerable!
307 HINT STEP 6 - VERIFY YOU CAN BE REACHED VIA IPv6
309     If your LFS machine is a server, meant for the public to reach, you have
310     many additional steps to perform. Firewall setup, ensuring others can reach
311     your device at its IPv6 address. Ensuring that all the packages you depend
312     on are setup with either IPv6 in mind
314 HINT STEP 7 - A FEW MINOR OTHER THINGS
316     There's always more to do. Here are a couple of things I happen to
317     remember:
319 HINT STEP 7A - ADD IPv6 DNS SERVERS TO /etc/resolv.conf
321     These aren't absolutely necessary, as resolving an IPv6 address can be done
322     in a query to a DNS carried in IPv6, but these are nice to have. Your DNS
323     provider will know what, if any, IPv6 addresses they have for their DNS
324     resolvers.
326 HINT STEP 7B - MONITOR YOUR IPv6 SETUP
328     Regular 'ipaddr' commands do not work. Use 'ip'. Examples:
330      ip -4 address:  returns list of IPv4 interface addresses
331      ip -4 route:    returns IPv4 routing table
332      ip -6 address:  returns list of IPv6 interface addresses
333      ip -6 route:    returns IPv6 routing table
335 HINT STEP 7C - A COMMON PROBLEM
337     Sometimes firewalls from our ISP can be set to filter IPv6 altogether or be
338     set with 'state' - allowing traffic not to be initiated from the outside.
339     Either of these might be contrary to what you want to have happen
340     (especially if your newly IPv6-capable machine is meant to be reached by
341     other systems on the Internet as a web server or something else.) - so you
342     may need to edit your ISP Gateway/Firewall/etc. settings.
344 HINT STEP 8 - MONITOR AND VERIFY, TRY USING EVERYTHING ON YOUR SYSTEM
346     You'll just need to, as soon as possible, try everything to make sure it
347     all works.
349 ACKNOWLEDGEMENTS:
351    * The Internet at large for providing many examples of IPv6 security 
352      and usage.
353    * The app developers for adding IPv6 support to their applications The
354    * providers of LFS - such a great base for a system!
356 CHANGELOG:
358 [2019-12-08] First version.
360 MODIFIED AND NEW SCRIPTS
362 Modifed script /sbin/ifup
364 #!/bin/sh
365 ########################################################################
366 # Begin /sbin/ifup
368 # Description : Interface Up
370 # Authors     : Nathan Coulson - nathan at linuxfromscratch.org
371 #               Kevin P. Fleming - kpfleming at linuxfromscratch.org
372 # Update      : Bruce Dubbs - bdubbs at linuxfromscratch.org
373 #               DJ Lucas - dj at linuxfromscratch.org
374 #               Joel Bion - jpbipv6hint at gmail.com
376 # Version     : LFS 9.0
378 # Notes       : The IFCONFIG variable is passed to the SERVICE script
379 #               in the /lib/services directory, to indicate what file the
380 #               service should source to get interface specifications.
382 ########################################################################
384 up()
386    log_info_msg "Bringing up the ${1} interface..."
388    if ip link show $1 > /dev/null 2>&1; then
389       link_status=`ip link show $1`
391       if [ -n "${link_status}" ]; then
392          if ! echo "${link_status}" | grep -q UP; then
393             ip link set $1 up
394          fi
395       fi
397    else
398       log_failure_msg "Interface ${IFACE} doesn't exist."
399       exit 1
400    fi
402    evaluate_retval
405 RELEASE="9.0"
407 USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
408 VERSTR="LFS ifup, version ${RELEASE}"
410 while [ $# -gt 0 ]; do
411     case "$1" in
412        --help | -h)     help="y"; break ;;
414        --version | -V)  echo "${VERSTR}"; exit 0 ;;
416        -*)              echo "ifup: ${1}: invalid option" >&2
417                         echo "${USAGE}" >& 2
418                         exit 2 ;;
420        *)               break ;;
421     esac
422 done
424 if [ -n "$help" ]; then
425     echo "${VERSTR}"
426     echo "${USAGE}"
427     echo
428     cat << HERE_EOF
429 ifup is used to bring up a network interface.  The interface
430 parameter, e.g. eth0 or eth0:2, must match the trailing part of the
431 interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
433 HERE_EOF
434     exit 0
437 file=/etc/sysconfig/ifconfig.${1}
439 # Skip backup files
440 [ "${file}" = "${file%""~""}" ] || exit 0
442 . /lib/lsb/init-functions
444 if [ ! -r "${file}" ]; then
445     log_failure_msg "Unable to bring up ${1} interface! ${file} is missing or cannot be accessed."
446     exit 1
449 .  $file
451 if [ "$IFACE" = "" ]; then
452     log_failure_msg "Unable to bring up ${1} interface! ${file} does not define an interface [IFACE]."
453     exit 1
456 # Do not process this service if started by boot, and ONBOOT
457 # is not set to yes
458 if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
459     exit 0
462 # Bring up the interface
463 if [ "$VIRTINT" != "yes" ]; then
464     up ${IFACE}
467 for S in ${SERVICE}; do
468    if [ ! -x "/lib/services/${S}" ]; then
469      MSG="\nUnable to process ${file}.  Either "
470      MSG="${MSG}the SERVICE '${S} was not present "
471      MSG="${MSG}or cannot be executed."
472      log_failure_msg "$MSG"
473      exit 1
474    fi
475 done
477 if [ "${SERVICE}" = "wpa" ]; then log_success_msg; fi
479 # Create/configure the interface
480 for S in ${SERVICE}; do
481    IFCONFIG=${file} /lib/services/${S} ${IFACE} up
482 done
484 # Set link up virtual interfaces
485 if [ "${VIRTINT}" == "yes" ]; then
486     up ${IFACE}
489 # Bring up any additional interface components
490 for I in $INTERFACE_COMPONENTS; do up $I; done
492 # Set MTU if requested. Check if MTU has a "good" value.
493 if test -n "${MTU}"; then
494     if [[ ${MTU} =~ ^[0-9]+$ ]] &amp;&amp; [[ $MTU -ge 68 ]] ; then
495        for I in $IFACE $INTERFACE_COMPONENTS; do
496           ip link set dev $I mtu $MTU;
497        done
498     else
499        log_info_msg2 "Invalid MTU $MTU"
500     fi
503 # Set the IPv4 default gateway if requested
504 if [ -n "${GATEWAY}" ]; then
505     if ip -4 route | grep -q default; then
506        log_warning_msg "IPv4 Gateway already set up; skipping."
507     else
508        log_info_msg "Adding default IPv4 gateway ${GATEWAY} to the ${IFACE} interface..."
509        ip route add default via ${GATEWAY} dev ${IFACE}
510        evaluate_retval
511     fi
514 # Set the IPv6 default gateway if requested (but only if an IPv6 address was
515 # given)
516 if [ "${IP6}" ]; then
517     if [ -n "${GATEWAY6}" ]; then
518        if ip -6 route | grep -q default; then
519           log_warning_msg "IPv6 gateway already set up; skipping."
520        else
521           log_info_msg "Adding default IPv6 gateway ${GATEWAY} to the ${IFACE} interface..."
522           ip -6 route add default via ${GATEWAY6} dev ${IFACE}
523           evaluate_retval
524        fi
525     fi
528 # End /sbin/ifup
531 +++++++++++++++++++++++++++++++++++++++++++++++++++
533 Modified script /sbin/ifdown
535 #!/bin/bash
536 ########################################################################
537 # Begin /sbin/ifdown
539 # Description : Interface Down
541 # Authors     : Nathan Coulson - nathan at linuxfromscratch.org
542 #               Kevin P. Fleming - kpfleming at linuxfromscratch.org
543 # Update      : Bruce Dubbs - bdubbs at linuxfromscratch.org
544 #               Joel Bion - jpbipv6hint at gmail.com
546 # Version     : LFS 9.0
548 # Notes       : the IFCONFIG variable is passed to the scripts found
549 #               in the /lib/services directory, to indicate what file the
550 #               service should source to get interface specifications.
552 ########################################################################
554 RELEASE="9.0"
556 USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
557 VERSTR="LFS ifdown, version ${RELEASE}"
559 while [ $# -gt 0 ]; do
560     case "$1" in
561        --help | -h)     help="y"; break ;;
563        --version | -V)  echo "${VERSTR}"; exit 0 ;;
565        -*)              echo "ifdown: ${1}: invalid option" >&2
566                         echo "${USAGE}" >& 2
567                         exit 2 ;;
569        *)               break ;;
570     esac
571 done
573 if [ -n "$help" ]; then
574     echo "${VERSTR}"
575     echo "${USAGE}"
576     echo
577     cat << HERE_EOF
578 ifdown is used to bring down a network interface.  The interface
579 parameter, e.g. eth0 or eth0:2, must match the trailing part of the
580 interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
582 HERE_EOF
583     exit 0
586 file=/etc/sysconfig/ifconfig.${1}
588 # Skip backup files
589 [ "${file}" = "${file%""~""}" ] || exit 0
591 . /lib/lsb/init-functions
593 if [ ! -r "${file}" ]; then
594     log_warning_msg "${file} is missing or cannot be accessed."
595     exit 1
598 . ${file}
600 if [ "$IFACE" = "" ]; then
601     log_failure_msg "${file} does not define an interface [IFACE]."
602     exit 1
605 # We only need to first service to bring down the interface
606 S=`echo ${SERVICE} | cut -f1 -d" "`
608 if ip link show ${IFACE} > /dev/null 2<&1; then
609     if [ -n "${S}" -a -x "/lib/services/${S}" ]; then
610       IFCONFIG=${file} /lib/services/${S} ${IFACE} down
611     else
612       MSG="Unable to process ${file}.  Either "
613       MSG="${MSG}the SERVICE variable was not set "
614       MSG="${MSG}or the specified service cannot be executed."
615       log_failure_msg "$MSG"
616       exit 1
617    fi
618 else
619     log_warning_msg "Interface ${1} doesn't exist."
622 # Leave the interface up if there are additional interfaces in the device
623 # However, for IPv6, we insist those adddresses must be global in scope,
624 # and not just one of the very many link-scope addresses IPv6 provides us.
626 link_status=`ip link show ${IFACE} 2>/dev/null`
628 if [ -n "${link_status}" ]; then
629     if [ "$(echo "${link_status}" | grep UP)" != "" ]; then
630        if [ "$(ip addr show ${IFACE} | grep 'inet ')" == "" -a 
631             "$(ip addr show ${IFACE} | grep 'inet6 ' | 
632             grep 'scope global')" == "" ]; then
633           log_info_msg "Bringing down the ${IFACE} interface..."
634           ip link set ${IFACE} down
635           evaluate_retval
636        fi
637     fi
640 # End /sbin/ifdown
642 New script /lib/services/ipv46-static, based off of ipv4-static
644 #!/bin/sh
645 ########################################################################
646 # Begin /lib/services/ipv46-static
648 # Description : IPV4 Static Boot Script
650 # Authors     : Nathan Coulson - nathan at linuxfromscratch.org
651 #               Kevin P. Fleming - kpfleming at linuxfromscratch.org
652 # Update      : Bruce Dubbs - bdubbs at linuxfromscratch.org
653 #             : Joel Bion - jpbipv6hint at gmail.com
655 # Version     : LFS 9.0
657 ########################################################################
659 . /lib/lsb/init-functions
660 . ${IFCONFIG}
662 args6=""
664 if [ -z "${IP}" ]; then
665     log_failure_msg "\nIP variable missing from ${IFCONFIG}, cannot continue."
666     exit 1
669 if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
670     log_warning_msg "\nPREFIX variable missing from ${IFCONFIG}, assuming 24."
671     PREFIX=24
672     args="${args} ${IP}/${PREFIX}"
674 elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
675     log_failure_msg "\nPREFIX and PEER both specified in ${IFCONFIG}, cannot continue."
676     exit 1
678 elif [ -n "${PREFIX}" ]; then
679     args="${args} ${IP}/${PREFIX}"
681 elif [ -n "${PEER}" ]; then
682     args="${args} ${IP} peer ${PEER}"
685 if [ -n "${LABEL}" ]; then
686     args="${args} label ${LABEL}"
689 if [ -n "${BROADCAST}" ]; then
690     args="${args} broadcast ${BROADCAST}"
693 if [ -n "${IP6}" ]; then
694      if [ -z "${PREFIX6}" ]; then
695          log_warning_msg = "\nPREFIX6 variable missing from {$IFCONFIG}, assuming 64."
696          PREFIX6=64
697      fi
698      args6="${args6} ${IP6}/${PREFIX6}"
701 case "${2}" in
702     up)
703        if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" = "" ]; then
705           # Cosmetic output
706           if ! $(echo ${SERVICE} | grep -q " "); then
707             log_info_msg2 "\n" # Terminate the previous message
708           fi
710           log_info_msg "Adding IPv4 address ${IP} to the ${1} interface..."
711           ip addr add ${args} dev ${1}
712           evaluate_retval
713        else
714           log_warning_msg "Cannot add IPv4 address ${IP} to ${1}.  Already present."
715        fi
717        if [ -n "${IP6}" ]; then
718            if [ "$(ip -6 addr show ${1} 2>/dev/null | grep ${IP6}/)" = "" ]; then
720               # Cosmetic output
721               if ! $(echo ${SERVICE} | grep -q " "); then
722                   log_info_msg2 "\n" # Terminate the previous message
723               fi
725               log_info_msg "Adding IPv6 address ${IP6} to the ${1} interface..."
726               ip -6 addr add ${args6} dev ${1}
727               evaluate_retval
728            else
729               log_warning_msg "Cannot add IPv6 address ${IP6} to ${1}.  Already present."
730            fi
731         fi
732     ;;
734     down)
735        if [ -n "${IP6}" ]; then
736            if [ "$(ip -6 addr show ${1} 2>/dev/null | grep ${IP6}/)" != "" ]; then
737               log_info_msg "Removing IPv6 address ${IP6} from the ${1} interface..."
738               ip -6 addr del ${args6} dev ${1}
739               evaluate_retval
740            fi
741        fi
742        if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" != "" ]; then
743           log_info_msg "Removing IPv4 address ${IP} from the ${1} interface..."
744           ip addr del ${args} dev ${1}
745           evaluate_retval
746        fi
748        # This code is removed because removing the last address REMOVES the
749        # default route from the routing table ALREADY
750        # if [ -n "${GATEWAY}" ]; then
751        #   # Only remove the gateway if there are no remaining ipv4 addresses
752        #   if [ "$(ip addr show ${1} 2>/dev/null | grep 'inet ')" == "" ]; then
753        #      log_info_msg "Removing IPv4 default gateway..."
754        #      ip route del default
755        #      evaluate_retval
756        #   fi
757        # fi
758     ;;
760     *)
761        echo "Usage: ${0} [interface] {up|down}"
762        exit 1
763     ;;
764 esac
766 # End /lib/services/ip46-static