#!/bin/sh # ===================================================================== # Projet : DARKWALL # Fichier : bin/ifdhcpenter.firewall # Auteur : Nicolas "DarkHack" Chapuis (c) 2026 # ================== DARKHACK ================== # [ darkweb.fr - system online ] # Powered by Perplexity, your AI assistant # https://www.perplexity.ai # ============================================== # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ===================================================================== LOG=/tmp/darkwall-dhcpRouteRadvdHelper.log log() { echo "$*" >> "$LOG" } run_ip() { log "+ $*" out="$("$@" 2>&1)" rc=$? log "rc=$rc out=$out" return "$rc" } # loop over the 4 possible prefixes: (empty), cur_, new_, old_ jsonParamDhcp="" first=1 for prefix in '' 'cur_' 'new_' 'old_'; do # loop over the DHCP variables passed to dhclient-script for basevar in reason interface medium alias_ip_address \ ip_address host_name network_number subnet_mask \ broadcast_address routers static_routes \ rfc3442_classless_static_routes \ domain_name domain_search domain_name_servers \ netbios_name_servers netbios_scope \ ntp_servers \ ip6_address ip6_prefix ip6_prefixlen \ dhcp6_domain_search dhcp6_name_servers do var="${prefix}${basevar}" content="" eval "content=\"\$$var\"" # show only variables with values set if [ -n "${content}" ]; then if [ "$first" -eq 1 ];then first=0 jsonParamDhcp="\"${var}\":\"${content}\"" else jsonParamDhcp="${jsonParamDhcp},\"${var}\":\"${content}\"" fi fi done done jsonParamDhcp="{${jsonParamDhcp}}" sh /etc/darkwall/bin/tryPipeMessage dhcp-enter "$( echo "${jsonParamDhcp}" | base64 | tr -d '[:space:]')" & log "===== $(date) =====" #log "ip -6 addr" #ip -6 addr >> "$LOG" #log "ip -6 route" #ip -6 route >> "$LOG" #log "ip -6 route show table local" #ip -6 route show table local >> "$LOG" ipSrc="${new_ip_address}" ipSrc="${ipSrc:-$( sh /etc/darkwall/bin/GetIpForIface ${interface} )}" if [ -n "$interface" ] && [ -n "$new_routers" ] && [ -n "$ipSrc" ]; then IFS_SAVE=$IFS IFS=',' set -- $new_routers IFS=$IFS_SAVE for new_router in "$@"; do if run_ip ip route get $new_router dev $interface;then if ! ip route show dev "$interface" | grep -q "default via $new_router"; then log "try Add Route '$new_router' on '$interface' by '$ipSrc'" >> "$LOG" if run_ip ip route add default via "$new_router" dev "$interface" src ${ipSrc} scope global; then log "route added $new_router by '$ipSrc'" >> "$LOG" elif run_ip ip route replace default via "$new_router" dev "$interface" src ${ipSrc} scope global; then log "route replaced $new_router by $ipSrc" >> "$LOG" else if ! ip route show dev "$interface" | grep -q "^default "; then log "!!!!!!! Fallback Route '$interface' (scope link)" >> "$LOG" run_ip ip route replace default dev "$interface" src ${ipSrc} scope link else log "default already present, no fallback" fi fi fi else log "Route not ready for '$new_router' on '$interface'" fi done #else # log "one of follow is empty: ipSrc:$ipSrc new_routers:$new_routers interface:$interface" fi if [ -f /etc/radvd.conf.pattern ];then case "$reason" in BOUND6|EXPIRE6|REBIND6|REBOOT6|RENEW6) if [ -n "$new_ip6_prefix" ]; then newPrefixMask=`echo "$new_ip6_prefix" | cut -d/ -f2` newPrefix=`echo "$new_ip6_prefix" | cut -d/ -f1` # adresse finale: prefix::1/mask → ici prefix est déjà fini par :: if ! ip -6 addr show | grep -q "$newPrefix"; then log "reconf radvd for:${newPrefix}/${newPrefixMask} $new_ip6_prefix" # Construction sûre de la commande sed: # on change de séparateur pour ne pas être gêné par les / evalSed="s|TheNewPrefix|$new_ip6_prefix|g" sed "$evalSed" /etc/radvd.conf.pattern > /etc/radvd.conf # et tu pourras ensuite: systemctl restart radvd fi fi ;; esac fi #log "after:" #ip -6 addr >> "$LOG" #ip -6 route >> "$LOG" #ip -6 route show table local >> "$LOG"