This file is indexed.

/usr/sbin/sgw_policy_routing_setup.sh is in olsrd 0.6.6.2-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash

set -e
set -u

###############################################################################
#
# SETTINGS
#
###############################################################################

declare IPVERSION_4="ipv4"
declare IPVERSION_6="ipv6"

declare MODE_GENERIC="generic"
declare MODE_OLSRIF="olsrif"
declare MODE_SGWSRVTUN="sgwsrvtun"
declare MODE_EGRESSIF="egressif"
declare MODE_SGWTUN="sgwtun"

declare ADDMODE_ADD="add"
declare ADDMODE_DEL="del"


###############################################################################
#
# HELPER FUNCTIONS
#
###############################################################################

function usage() {
  echo ""
  echo "The script was called as:"
  echo "  ${script} ${arguments[@]:-}"
  echo ""
  echo "Usage:"
  echo "  ${script} ipVersion mode addMode [ifname [ifmark]]"
  echo "    - ipVersion: ${IPVERSION_4} or ${IPVERSION_6}"
  echo "    - mode     : ${MODE_GENERIC}, ${MODE_OLSRIF}, ${MODE_SGWSRVTUN}, ${MODE_EGRESSIF} or ${MODE_SGWTUN}"
  echo "    - addMode  : ${ADDMODE_ADD} or ${ADDMODE_DEL}"
  echo "    - ifname   : an interface name, not relevant for generic mode"
  echo "    - ifmark   : an interface marking (number), only relevant for ${MODE_EGRESSIF} and ${MODE_SGWTUN} modes"
}

function error() {
  local -i firstLine=1
  while [ ${#} -gt 0 ]; do
    if [ ${firstLine} -eq 1 ]; then
      echo "Error: ${1}"
    else
      echo "       ${1}"
    fi
    firstLine=0
    shift 1
  done
}


###############################################################################
#
# MODE FUNCTIONS
#
###############################################################################

function generic() {
  "${IPTABLES}" ${IPTABLES_ARGS} -t mangle "${ADDMODE_IPTABLES}" OUTPUT -j CONNMARK --restore-mark
}

function olsrif() {
  "${IPTABLES}" ${IPTABLES_ARGS} -t mangle "${ADDMODE_IPTABLES}" PREROUTING -i "${1}" -j CONNMARK --restore-mark
}

function sgwsrvtun() {
  "${IPTABLES}" ${IPTABLES_ARGS} -t mangle "${ADDMODE_IPTABLES}" PREROUTING -i "${1}" -j CONNMARK --restore-mark
}

function egressif() {
  "${IPTABLES}" ${IPTABLES_ARGS} -t mangle "${ADDMODE_IPTABLES}" POSTROUTING -m conntrack --ctstate NEW -o "${1}" -j CONNMARK --set-mark "${2}"
  "${IPTABLES}" ${IPTABLES_ARGS} -t mangle "${ADDMODE_IPTABLES}" INPUT       -m conntrack --ctstate NEW -i "${1}" -j CONNMARK --set-mark "${2}"
  "${IP}" ${IP_ARGS} rule "${ADDMODE_IP}" fwmark "${2}" table "${2}" pref "${2}"
}

function sgwtun() {
  "${IPTABLES}" ${IPTABLES_ARGS} -t mangle "${ADDMODE_IPTABLES}" POSTROUTING -m conntrack --ctstate NEW -o "${1}" -j CONNMARK --set-mark "${2}"
  "${IP}" ${IP_ARGS} rule "${ADDMODE_IP}" fwmark "${2}" table "${2}" pref "${2}"
}


###############################################################################
#
# MAIN
#
###############################################################################

declare script="${0}"
declare -a arguments=( ${@} )
declare -i argc=${#}

# we always need 3 arguments, check it
if [ ${argc} -lt 3 ]; then
  error "Need at least 3 arguments"
  usage
  exit 1
fi

# get first 3 arguments
declare ipVersion=${1}
declare mode="${2}"
declare addMode="${3}"
shift 3
argc=${#}

# check IP version argument
if [ ! "${ipVersion}" == "${IPVERSION_4}" ] && \
   [ ! "${ipVersion}" == "${IPVERSION_6}" ]; then
  error "Illegal IP version"
  usage
  exit 1
fi

# check mode argument
if [ ! "${mode}" == "${MODE_GENERIC}" ] && \
   [ ! "${mode}" == "${MODE_OLSRIF}" ] && \
   [ ! "${mode}" == "${MODE_SGWSRVTUN}" ] && \
   [ ! "${mode}" == "${MODE_EGRESSIF}" ] && \
   [ ! "${mode}" == "${MODE_SGWTUN}" ]; then
  error "Illegal mode"
  usage
  exit 1
fi

# check addMode argument
if [ ! "${addMode}" == "${ADDMODE_ADD}" ] && \
   [ ! "${addMode}" == "${ADDMODE_DEL}" ]; then
  error "Illegal addMode"
  usage
  exit 1
fi

# check argument count for all modes
if ([ "${mode}" == "${MODE_GENERIC}" ]   && [ ${argc} -ne 0 ]) || \
   ([ "${mode}" == "${MODE_OLSRIF}" ]    && [ ${argc} -ne 1 ]) || \
   ([ "${mode}" == "${MODE_SGWSRVTUN}" ] && [ ${argc} -ne 1 ]) || \
   ([ "${mode}" == "${MODE_EGRESSIF}"  ] && [ ${argc} -ne 2 ]) || \
   ([ "${mode}" == "${MODE_SGWTUN}"  ]   && [ ${argc} -ne 2 ]); then
  error "Not enough arguments or too many arguments"
  usage
  exit 1
fi

# process ipVersion argument
declare IPTABLES="iptables"
declare IPTABLES_ARGS=""
declare IP="ip"
declare IP_ARGS="-4"
if [ "${ipVersion}" == "${IPVERSION_6}" ]; then
  IPTABLES="ip6tables"
  IPTABLES_ARGS=""
  IP="ip"
  IP_ARGS="-6"
fi

# process addMode argument
declare ADDMODE_IPTABLES="-D"
declare ADDMODE_IP="del"
if [ "${addMode}" == "${ADDMODE_ADD}" ]; then
  # first call the delete mode to remove any left-over rules
  set +e
  "${mode}" "${@}" 2> /dev/null
  set -e

  ADDMODE_IPTABLES="-I"
  ADDMODE_IP="add"
fi

# call the mode
"${mode}" "${@}"