net/quagga: fix r23654
[packages.git] / net / quagga / patches / 100-quagga_multipath_caching_policy.patch
1 --- a/configure.ac
2 +++ b/configure.ac
3 @@ -397,7 +397,7 @@ dnl -------------------------
4  AC_CHECK_HEADERS([stropts.h sys/ksym.h sys/times.h sys/select.h \
5         sys/types.h linux/version.h netdb.h asm/types.h \
6         sys/param.h limits.h signal.h libutil.h \
7 -       sys/socket.h netinet/in.h time.h sys/time.h])
8 +       sys/socket.h netinet/in.h time.h sys/time.h linux/ip_mp_alg.h])
9  
10  dnl Utility macro to avoid retyping includes all the time
11  m4_define([QUAGGA_INCLUDES],
12 --- a/lib/command.h
13 +++ b/lib/command.h
14 @@ -101,6 +101,7 @@ enum node_type
15    DUMP_NODE,                   /* Packet dump node. */
16    FORWARDING_NODE,             /* IP forwarding node. */
17    PROTOCOL_NODE,                /* protocol filtering node */
18 +  MULTIPATH_NODE,              /* Multipath policy node */
19    VTY_NODE,                    /* Vty node. */
20  };
21  
22 @@ -272,6 +273,7 @@ struct desc
23  /* Common descriptions. */
24  #define SHOW_STR "Show running system information\n"
25  #define IP_STR "IP information\n"
26 +#define MULTIPATH_STR "Configure multipath policy\n"
27  #define IPV6_STR "IPv6 information\n"
28  #define NO_STR "Negate a command or set its defaults\n"
29  #define REDIST_STR "Redistribute information from another routing protocol\n"
30 --- a/lib/zebra.h
31 +++ b/lib/zebra.h
32 @@ -176,6 +176,10 @@ typedef int socklen_t;
33  #define RT_TABLE_MAIN          0
34  #endif /* HAVE_NETLINK */
35  
36 +#ifdef HAVE_LINUX_IP_MP_ALG_H
37 +#include <linux/ip_mp_alg.h>
38 +#endif /* HAVE_LINUX_IP_MP_ALG_H */
39 +
40  #ifdef HAVE_NETDB_H
41  #include <netdb.h>
42  #endif /* HAVE_NETDB_H */
43 --- a/zebra/main.c
44 +++ b/zebra/main.c
45 @@ -44,6 +44,7 @@
46  struct zebra_t zebrad =
47  {
48    .rtm_table_default = 0,
49 +  .mpath = 0,
50  };
51  
52  /* process id. */
53 --- /dev/null
54 +++ b/zebra/multipath.h
55 @@ -0,0 +1,37 @@
56 +/*
57 + * multipath policy names.
58 + *
59 + * This file is part of Quagga routing suite.
60 + *
61 + * Quagga is free software; you can redistribute it and/or modify it
62 + * under the terms of the GNU General Public License as published by the
63 + * Free Software Foundation; either version 2, or (at your option) any
64 + * later version.
65 + *
66 + * Quagga is distributed in the hope that it will be useful, but
67 + * WITHOUT ANY WARRANTY; without even the implied warranty of
68 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
69 + * General Public License for more details.
70 + *
71 + * You should have received a copy of the GNU General Public License
72 + * along with GNU Zebra; see the file COPYING.  If not, write to the Free
73 + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
74 + * 02111-1307, USA.
75 + */
76 +
77 +#ifndef ZEBRA_MULTIPATH_H
78 +#define ZEBRA_MULTIPATH_H
79 +#include <zebra.h>
80 +
81 +#ifdef HAVE_LINUX_IP_MP_ALG_H
82 +
83 +static char *mp_alg_names[IP_MP_ALG_MAX+1] = {
84 +                        [IP_MP_ALG_NONE] = "none",
85 +                        [IP_MP_ALG_RR] = "rr",
86 +                        [IP_MP_ALG_DRR] = "drr",
87 +                        [IP_MP_ALG_RANDOM] = "random",
88 +                        [IP_MP_ALG_WRANDOM] = "wrandom"
89 +                       };
90 +#endif
91 +#endif
92 +
93 --- a/zebra/rt_netlink.c
94 +++ b/zebra/rt_netlink.c
95 @@ -36,6 +36,7 @@
96  #include "thread.h"
97  #include "privs.h"
98  
99 +#include "multipath.h"
100  #include "zebra/zserv.h"
101  #include "zebra/rt.h"
102  #include "zebra/redistribute.h"
103 @@ -1694,6 +1695,16 @@ netlink_route_multipath (int cmd, struct
104        if (src)
105          addattr_l (&req.n, sizeof req, RTA_PREFSRC, &src->ipv4, bytelen);
106  
107 +#ifdef HAVE_LINUX_IP_MP_ALG_H
108 +       if (zebrad.mpath != IP_MP_ALG_NONE)
109 +       {
110 +             if (IS_ZEBRA_DEBUG_KERNEL)
111 +                        zlog_debug("netlink_route_multipath() (multihop): "
112 +                                  "multipath policy : %s",mp_alg_names[zebrad.mpath]);
113 +
114 +            addattr_l (&req.n, 1024, RTA_MP_ALGO, &zebrad.mpath, sizeof(zebrad.mpath));
115 +       }
116 +#endif 
117        if (rta->rta_len > RTA_LENGTH (0))
118          addattr_l (&req.n, 1024, RTA_MULTIPATH, RTA_DATA (rta),
119                     RTA_PAYLOAD (rta));
120 --- a/zebra/zserv.c
121 +++ b/zebra/zserv.c
122 @@ -36,6 +36,7 @@
123  #include "privs.h"
124  #include "network.h"
125  #include "buffer.h"
126 +#include "multipath.h"
127  
128  #include "zebra/zserv.h"
129  #include "zebra/router-id.h"
130 @@ -1120,6 +1121,9 @@ zebra_client_create (int sock)
131    /* Set table number. */
132    client->rtm_table = zebrad.rtm_table_default;
133  
134 +  /* Set multipath policy */
135 +  client->mpath = zebrad.mpath;
136 +
137    /* Add this client to linked list. */
138    listnode_add (zebrad.client_list, client);
139    
140 @@ -1697,6 +1701,91 @@ static struct cmd_node forwarding_node =
141  };
142  
143  \f
144 +#ifdef HAVE_LINUX_IP_MP_ALG_H
145 +DEFUN (multipath_rr,
146 +       multipath_rr_cmd,
147 +       "multipath rr",
148 +       MULTIPATH_STR
149 +       "Round Robin multipath policy")
150 +{
151 +         zebrad.mpath=IP_MP_ALG_RR;
152 +         return CMD_SUCCESS;
153 +}
154 +
155 +DEFUN (multipath_drr,
156 +       multipath_drr_cmd,
157 +       "multipath drr",
158 +       MULTIPATH_STR
159 +       "Device round robin multipath policy")
160 +{
161 +         zebrad.mpath=IP_MP_ALG_DRR;
162 +         return CMD_SUCCESS;
163 +}
164 +
165 +DEFUN (multipath_random,
166 +       multipath_random_cmd,
167 +       "multipath random",
168 +       MULTIPATH_STR
169 +       "Random multipath policy")
170 +{
171 +         zebrad.mpath=IP_MP_ALG_RANDOM;
172 +         return CMD_SUCCESS;
173 +}
174 +
175 +DEFUN (multipath_wrandom,
176 +       multipath_wrandom_cmd,
177 +       "multipath wrandom",
178 +       MULTIPATH_STR
179 +       "Weighted random multipath policy")
180 +{
181 +         zebrad.mpath=IP_MP_ALG_WRANDOM;
182 +         return CMD_SUCCESS;
183 +}
184 +
185 +DEFUN (no_multipath,
186 +       no_multipath_cmd,
187 +       "no multipath",
188 +       NO_STR
189 +       MULTIPATH_STR
190 +       "Remove multipath policy")
191 +{
192 +       zebrad.mpath=IP_MP_ALG_NONE;
193 +       return CMD_SUCCESS;
194 +}
195 +
196 +DEFUN (show_multipath,
197 +       show_multipath_cmd,
198 +       "show multipath",
199 +       SHOW_STR
200 +       "Show multipath policy")
201 +{
202 +        vty_out (vty, "multipath %s%s", mp_alg_names[zebrad.mpath],
203 +                            VTY_NEWLINE);
204 +       return CMD_SUCCESS;
205 +}
206 +
207 +/* multipath policy configuration write function. */
208 +static int
209 +config_write_multipath (struct vty *vty)
210 +{
211 +
212 +
213 +  if (zebrad.mpath)
214 +    vty_out (vty, "multipath %s%s", mp_alg_names[zebrad.mpath],
215 +            VTY_NEWLINE);
216 +  return 0;
217 +}
218 +
219 +/* table node for multipath policy. */
220 +struct cmd_node multipath_node =
221 +{
222 +         MULTIPATH_NODE,
223 +         "",                           
224 +         1
225 +};
226 +
227 +#endif /* HAVE_LINUX_IP_MP_ALG_H */
228 +
229  /* Initialisation of zebra and installation of commands. */
230  void
231  zebra_init (void)
232 @@ -1708,6 +1797,10 @@ zebra_init (void)
233    install_node (&table_node, config_write_table);
234    install_node (&forwarding_node, config_write_forwarding);
235  
236 +#ifdef HAVE_LINUX_IP_MP_ALG_H
237 +  install_node (&multipath_node, config_write_multipath);
238 +#endif
239 +
240    install_element (VIEW_NODE, &show_ip_forwarding_cmd);
241    install_element (ENABLE_NODE, &show_ip_forwarding_cmd);
242    install_element (CONFIG_NODE, &ip_forwarding_cmd);
243 @@ -1718,6 +1811,14 @@ zebra_init (void)
244    install_element (VIEW_NODE, &show_table_cmd);
245    install_element (ENABLE_NODE, &show_table_cmd);
246    install_element (CONFIG_NODE, &config_table_cmd);
247 +#ifdef HAVE_LINUX_IP_MP_ALG_H
248 +  install_element (CONFIG_NODE, &multipath_rr_cmd);
249 +  install_element (CONFIG_NODE, &multipath_drr_cmd);
250 +  install_element (CONFIG_NODE, &multipath_random_cmd);
251 +  install_element (CONFIG_NODE, &multipath_wrandom_cmd);
252 +  install_element (CONFIG_NODE, &no_multipath_cmd);
253 +  install_element (ENABLE_NODE, &show_multipath_cmd);
254 +#endif /* HAVE_LINUX_IP_MP_ALG_H */
255  #endif /* HAVE_NETLINK */
256  
257  #ifdef HAVE_IPV6
258 --- a/zebra/zserv.h
259 +++ b/zebra/zserv.h
260 @@ -55,6 +55,9 @@ struct zserv
261    /* default routing table this client munges */
262    int rtm_table;
263  
264 +  /* multipath policy */
265 +  u_int32_t mpath;
266 +
267    /* This client's redistribute flag. */
268    u_char redist[ZEBRA_ROUTE_MAX];
269  
270 @@ -78,6 +81,9 @@ struct zebra_t
271    /* default table */
272    int rtm_table_default;
273  
274 +  /* multipath policy */
275 +  u_int32_t mpath;
276 +
277    /* rib work queue */
278    struct work_queue *ribq;
279    struct meta_queue *mq;