summaryrefslogtreecommitdiff
path: root/scripts/vyatta-update-arp-params
blob: 094d07519181cbcee5c8f4ca90b892939a0dc325 (plain)
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
#!/bin/bash
#
# Module: vyatta-update-arp-params
#
# **** License ****
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2009 Vyatta, Inc.
# All Rights Reserved.
#
# Author: Mohit Mehta
# Date: February 2009
# Description: Update [ARP (IPv4)|Neighbor (IPV6)] Parameters
#
# **** End License ****
#

#
# subroutines
#

print_usage()
{
    echo "Usage:"
    echo -e "\t$0 syntax-check <type of arp paramter> <value of arp paramter> <ipv4/ipv6>"
    echo -e "\t$0 update <type of arp paramter> <value of arp paramter> <ipv4/ipv6>"
    echo -e "\t$0 delete <type of arp paramter> <ipv4/ipv6>"
}

syntax_arp_param ()
{
 arp_type=$1
 arp_value=$2
 ip_type=$3

 case "$arp_type" in

        table-size)
        allowed_values=(1024 2048 4096 8192 16384)
        allowed_values_len=${#allowed_values[*]}
        i=0
        while [ $i -lt $allowed_values_len ]; do
         if [ "${allowed_values[$i]}" == "$arp_value" ] ; then
          exit 0
         fi
         let i++
        done
        echo "Allowed values for ARP table-size - 1024 2048 4096 8192 16384"
        exit 1
        ;;

        *)
         echo Invalid arp parameter $arp_type to set
         exit 1
        ;;
 esac
}

update_arp_param ()
{
 arp_type=$1
 arp_value=$2
 ip_type=$3

 case "$arp_type" in

        table-size)
        let softmax=$arp_value\/2;
        let min=$arp_value\/8;
        sudo sysctl -q net.$ip_type.neigh.default.gc_thresh3=$arp_value
        sudo sysctl -q net.$ip_type.neigh.default.gc_thresh2=$softmax
        sudo sysctl -q net.$ip_type.neigh.default.gc_thresh1=$min
        ;;

        *)
         echo Invalid arp parameter $arp_type to update
        ;;
 esac
}

delete_arp_param ()
{
 arp_type=$1
 ip_type=$2

 case "$arp_type" in

        table-size)
        sudo sysctl -q net.$ip_type.neigh.default.gc_thresh3=1024
        sudo sysctl -q net.$ip_type.neigh.default.gc_thresh2=512
        sudo sysctl -q net.$ip_type.neigh.default.gc_thresh1=128
        ;;

        *)
         echo Invalid arp parameter $arp_type to update
        ;;
 esac
}

#
# main
#

case "$1" in
    syntax-check)
        if [ $# -ne 4 ]; then
                print_usage
                exit 1
        fi
        syntax_arp_param $2 $3 $4
        ;;

    update)
        if [ $# -ne 4 ]; then
                print_usage
                exit 1
        fi
        update_arp_param $2 $3 $4
        ;;

    delete)
        if [ $# -ne 3 ]; then
                print_usage
                exit 1
        fi
        delete_arp_param $2 $3
        ;;


    *)
        print_usage
        exit 1
        ;;

esac

exit 0

# end of file