• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Dual NIC clients

    Scheduled Pinned Locked Moved
    Linux Problems
    3
    25
    8.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Wayne WorkmanW
      Wayne Workman @Quazz
      last edited by

      @Quazz very nice. I read it’s description, but the one below it caught my eye:

      grcan.select= [HW] Select which physical interface to use. Format: 0 | 1 Default: 0

      So perhaps try this for the host’s kernel arguments (web gui -> host management -> desired host -> kernel arguments)

      grcan.select=1

      See what happens?

      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
      Daily Clean Installation Results:
      https://fogtesting.fogproject.us/
      FOG Reporting:
      https://fog-external-reporting-results.fogproject.us/

      1 Reply Last reply Reply Quote 0
      • T
        tag
        last edited by

        @Quazz and @Wayne-Workman

        Thanks for the suggestions.

        I tried playing around with grcan.enable0=[0|1] and grcan.enable1=[0|1] as well as grcan.select=[0|1] but none had any effect. The kernel continues to choose the slower link in most cases. Seemed promising, though…

        What I do notice for the first time, though, is that whatever NIC is not chosen is disabled. I hadn’t noticed as I can’t see the backs of the boxes very well. Here it is also obvious that the active NIC changes on occasion, as the LEDs die on the disabled NIC.

        Wayne WorkmanW 1 Reply Last reply Reply Quote 0
        • Wayne WorkmanW
          Wayne Workman @tag
          last edited by Wayne Workman

          @tag I think you’re going to have to build a custom init. You can change the fog.upload and fog.download scripts. The idea would be to use shell script to determine which interface is on the right network, and then disable the other interface (or enable it). It should be pretty simple.

          How experienced are you with shell scripting?

          Also, here’s a link on how to unpack and re-pack the inits:
          https://wiki.fogproject.org/wiki/index.php?title=Build_FOG_file_system_with_BuildRoot

          I’m willing to help do this - but I wouldn’t have time until tonight to mess with it.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
          Daily Clean Installation Results:
          https://fogtesting.fogproject.us/
          FOG Reporting:
          https://fog-external-reporting-results.fogproject.us/

          1 Reply Last reply Reply Quote 0
          • T
            tag
            last edited by tag

            @Wayne-Workman

            Thanks for the reply.

            Seems kind of inflexible, though… The same init is used for all, right? We even have some clients with three NICs at other locations… If it has to take various hw scenarios into account, it might take some fancy scripting.

            I know some basic scripting but nothing really fancy.

            The only way to determine the correct interface would be to filter on IP, as I see it.

            So maybe a list of interfaces and then for each ethX in the list:

            #!/bin/csh
            
            set nwid = X.X.X
            set list = (eth0 eth1)
            
            foreach eth ($list)
              set ip = `ifconfig $eth | grep inet | awk '{print $2}' | sed 's/addr://' | cut -c-10 `
              if ($ip == $nwid) then
                  ifup $eth else
                  ifdown $eth
              endif
            end
            

            That would in my case get the network ID of the correct network and other disimilar outputs from the other interfaces in the list which could then be compared to a set value of the correct network ID. Based on that comparison you could then turn on or off the interfaces.

            I’m sure someone else could do something a lot niftier.

            I haven’t tested any of this and it might screw up if the number of interfaces actually present is different from the number in the list.

            Wayne WorkmanW 1 Reply Last reply Reply Quote 0
            • Wayne WorkmanW
              Wayne Workman @tag
              last edited by

              @tag You’ve got the right idea - but that specific code is inflexible.

              Tonight I’ll put something together that will take the IPs, and the subnet mask, and calculate the subnet ID and use that for comparison.

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
              Daily Clean Installation Results:
              https://fogtesting.fogproject.us/
              FOG Reporting:
              https://fog-external-reporting-results.fogproject.us/

              1 Reply Last reply Reply Quote 0
              • T
                tag
                last edited by

                @Wayne-Workman
                Thanks again.

                Yes, that code will only work on the specific network defined in $nwid and if the kernel names the interfaces ethX and probably only if the number of interfaces match that particular piece of hw…

                Mighty nice of you to help me out here… Appreciate it.

                Thanks.

                Wayne WorkmanW 1 Reply Last reply Reply Quote 0
                • Wayne WorkmanW
                  Wayne Workman @tag
                  last edited by

                  @tag Well the way I write it, it’ll work with however many NICs a system has. We will need to use the new feature that @Tom-Elliott so kindly implemented maybe a month ago, the host’s Host Init field. Basically we will build an init for each of your subnets, then use groups to assign the right inits to the right computers - so that those computers in those subnets use the correct interface.

                  Sounds like a lot - but I really don’t think it is. I think this is going to be very easy.

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                  Daily Clean Installation Results:
                  https://fogtesting.fogproject.us/
                  FOG Reporting:
                  https://fog-external-reporting-results.fogproject.us/

                  1 Reply Last reply Reply Quote 0
                  • Wayne WorkmanW
                    Wayne Workman
                    last edited by Wayne Workman

                    I’ve been working on this.

                    This is my first go-round with a custom init so I’m asking that @Sebastian-Roth and @Tom-Elliott and @george1421 to take a look, too.

                    I’ve not tested, as I don’t readily have available a machine with multiple interfaces, but I think I’ve got a universal init that you can pass a custom kernel argument to, which will ensure the correct interface is up, and others are down. So far, I’ve coded for three possible interfaces. I already had many of these functions already written in another project I’ve been working on.

                    in the init, I’ve edited the file /usr/share/fog/lib/funcs.sh to include these functions:

                    cidr2mask() {
                            #Expects CIDR notation (a single integer between 0 and 32)
                            local i=""
                            local mask=""
                            local full_octets=$(($1/8))
                            local partial_octet=$(($1%8))
                            for ((i=0;i<4;i+=1)); do
                            if [[ $i -lt $full_octets ]]; then
                                    mask+=255
                            elif [[ $i -eq $full_octets ]]; then
                                    mask+=$((256 - 2**(8-$partial_octet)))
                            else
                                    mask+=0
                            fi
                                    test $i -lt 3 && mask+=.
                            done
                            echo $mask
                    }
                    
                    getCidr() {
                            #Expects an interface name to be passed.
                            local cidr
                            cidr=$(ip -f inet -o addr | grep $1 | awk -F'[ /]+' '/global/ {print $5}' | head -n2 | tail -n1)
                            echo $cidr
                    }
                    mask2network() {
                            #Expects IP address passed 1st, and Subnet Mask passed 2nd.
                            OIFS=$IFS
                            IFS='.'
                            read -r i1 i2 i3 i4 <<< "$1"
                            read -r m1 m2 m3 m4 <<< "$2"
                            IFS=$OIFS
                            printf "%d.%d.%d.%d\n"  "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
                    }
                    GetInterfaceInfo() {
                    	DIR="/"
                    
                    	ip link show > $DIR/interfaces.txt
                    
                    	interface1name="$(sed -n '3p' $DIR/interfaces.txt)"
                    	interface2name="$(sed -n '5p' $DIR/interfaces.txt)"
                    	interface3name="$(sed -n '7p' $DIR/interfaces.txt)"
                    
                    
                    	rm -f $DIR/interfaces.txt
                    
                    	echo $interface1name | cut -d \: -f2 | cut -c2- > $DIR/interface1name.txt
                    	echo $interface2name | cut -d \: -f2 | cut -c2- > $DIR/interface2name.txt
                    	echo $interface3name | cut -d \: -f2 | cut -c2- > $DIR/interface3name.txt	
                    
                    	interface1name="$(cat $DIR/interface1name.txt)"
                    	interface2name="$(cat $DIR/interface2name.txt)"
                    	interface2name="$(cat $DIR/interface2name.txt)"
                    
                    	rm -f $DIR/interface1name.txt
                    	rm -f $DIR/interface2name.txt
                    	rm -f $DIR/interface3name.txt
                    
                    	#Bring up interfaces.
                    
                    	echo “iface $interface1name inet dhcp” >>/etc/network/interfaces
                    	echo “iface $interface2name inet dhcp” >>/etc/network/interfaces
                    	echo “iface $interface3name inet dhcp” >>/etc/network/interfaces
                    
                    
                    
                    	ip link set $interface1name up
                    	ip link set $interface2name up
                    	ip link set $interface3name up
                    	sleep 4
                    
                    
                    
                    
                    	interface1ip="$(/sbin/ip addr show | grep $interface1name | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*")"
                    
                    	interface2ip="$(/sbin/ip addr show | grep $interface2name | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*")"
                    
                    	interface3ip="$(/sbin/ip addr show | grep $interface3name | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*")"
                    
                    
                    	if [[ -z $interface1ip ]]; then
                    		interface1ip=127.0.0.1
                    	fi
                    
                    	if [[ -z $interface2ip ]]; then 
                    		interface2ip=127.0.0.1
                    	fi
                    
                    	if [[ -z $interface3ip ]]; then 
                                    interface3ip=127.0.0.1
                            fi
                    	
                    	interface1network=$(mask2network $interface1ip $(cidr2mask $(getCidr $interface1name)))
                    	interface2network=$(mask2network $interface2ip $(cidr2mask $(getCidr $interface2name)))
                    	interface3network=$(mask2network $interface3ip $(cidr2mask $(getCidr $interface3name)))
                    
                    
                    
                    
                    
                    }
                    
                    setCorrectInterface() {
                    for arg in $(cat /proc/cmdline) do  
                        echo $arg | grep -q USE_NETWORK
                        if [ $? == 0 ] then      
                            val=$(echo $arg | cut -d= -f2)
                            desiredNetwork=$val
                        fi
                    done
                    
                    GetInterfaceInfo
                    
                    if [[ $interface1network==$desiredNetwork ]] then
                            ip link set $interface1name up
                            ip link set $interface2name down
                            ip link set $interface3name down
                    elif [[ $interface2network==$desiredNetwork ]] then
                    	ip link set $interface1name down
                           	ip link set $interface2name up
                            ip link set $interface3name down
                    else [[ $interface3network==$desiredNetwork ]] then
                    	ip link set $interface1name down
                            ip link set $interface2name down
                            ip link set $interface3name up
                    fi
                    
                    
                    
                    }
                    

                    And I’ve added a call to the main function in the main fog script file /bin/fog between the usb part and the task calling, around line 10 like this:

                    #!/bin/bash
                    . /usr/share/fog/lib/funcs.sh
                    ### If USB Boot device we need a way to get the kernel args properly
                    if [[ $boottype == usb && ! -z $web ]]; then
                        mac=$(getMACAddresses)
                        wget -q -O /tmp/hinfo.txt "http://${web}service/hostinfo.php?mac=$mac"
                        [[ -f /tmp/hinfo.txt ]] && . /tmp/hinfo.txt
                    fi
                    
                    setCorrectInterface
                    
                    if [[ -n $mode && $mode != +(*debug*) ]]; then
                        case $mode in
                            wipe)
                                fog.wipe
                                ;;
                            checkdisk)
                                fog.testdisk
                                ;;
                            photorec)
                                fog.photorec
                                ;;
                            badblocks)
                                fog.surfacetest
                                ;;
                            clamav)
                                fog.av
                                ;;
                            autoreg)
                                fog.auto.reg
                                ;;
                            manreg)
                                fog.man.reg
                                ;;
                            inventory)
                                fog.inventory
                                ;;
                            capone)
                                fog.capone
                                ;;
                            winpassreset)
                                fog.chntpw
                                ;;
                            quickimage)
                                fog.quickimage
                                ;;
                            sysinfo)
                                fog.sysinfo
                                ;;
                            "donate.full")
                                fog.donatefull
                                ;;
                            *)
                                handleError "Fatal Error: Unknown mode :: $mode ($0)\n   Args Passed: $*"
                                ;;
                        esac
                    else
                        case $type in
                            down)
                                fog.download
                                ;;
                            up)
                                fog.upload
                                ;;
                            *)
                                [[ -z $type ]] && type="Null"
                                handleError "Fatal Error: Unknown request type :: $type"
                                ;;
                        esac
                    fi
                    

                    With modifications to the init like this (and using fog trunk), You’d simply specify this custom init, and pass the kernel argument for the network you want to use. For example:

                    0_1467251975872_USE_NETWORK.png

                    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                    Daily Clean Installation Results:
                    https://fogtesting.fogproject.us/
                    FOG Reporting:
                    https://fog-external-reporting-results.fogproject.us/

                    1 Reply Last reply Reply Quote 1
                    • T
                      tag
                      last edited by

                      @Wayne-Workman

                      That would work nicely, seeing you can use different inits. I didn’t know that as it is not possible in 1.2.0.

                      The caveat is that I would have to redo the server as trunk requires a newer Ubuntu according to @Quazz.

                      Wayne WorkmanW 1 Reply Last reply Reply Quote 0
                      • Wayne WorkmanW
                        Wayne Workman @tag
                        last edited by

                        @tag correct. No getting around that.

                        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                        Daily Clean Installation Results:
                        https://fogtesting.fogproject.us/
                        FOG Reporting:
                        https://fog-external-reporting-results.fogproject.us/

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 2 / 2
                        • First post
                          Last post

                        207

                        Online

                        12.1k

                        Users

                        17.3k

                        Topics

                        155.3k

                        Posts
                        Copyright © 2012-2024 FOG Project