1 /* route-map for interface.
2 * Copyright (C) 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 struct hash
*ifrmaphash
;
33 static void (*if_rmap_add_hook
) (struct if_rmap
*) = NULL
;
34 static void (*if_rmap_delete_hook
) (struct if_rmap
*) = NULL
;
36 static struct if_rmap
*
41 new = XCALLOC (MTYPE_IF_RMAP
, sizeof (struct if_rmap
));
47 if_rmap_free (struct if_rmap
*if_rmap
)
50 XFREE (MTYPE_IF_RMAP_NAME
, if_rmap
->ifname
);
52 if (if_rmap
->routemap
[IF_RMAP_IN
])
53 XFREE (MTYPE_IF_RMAP_NAME
, if_rmap
->routemap
[IF_RMAP_IN
]);
54 if (if_rmap
->routemap
[IF_RMAP_OUT
])
55 XFREE (MTYPE_IF_RMAP_NAME
, if_rmap
->routemap
[IF_RMAP_OUT
]);
57 XFREE (MTYPE_IF_RMAP
, if_rmap
);
61 if_rmap_lookup (const char *ifname
)
64 struct if_rmap
*if_rmap
;
67 key
.ifname
= (char *)ifname
;
69 if_rmap
= hash_lookup (ifrmaphash
, &key
);
75 if_rmap_hook_add (void (*func
) (struct if_rmap
*))
77 if_rmap_add_hook
= func
;
81 if_rmap_hook_delete (void (*func
) (struct if_rmap
*))
83 if_rmap_delete_hook
= func
;
87 if_rmap_hash_alloc (void *arg
)
89 struct if_rmap
*ifarg
= arg
;
90 struct if_rmap
*if_rmap
;
92 if_rmap
= if_rmap_new ();
93 if_rmap
->ifname
= XSTRDUP (MTYPE_IF_RMAP_NAME
, ifarg
->ifname
);
98 static struct if_rmap
*
99 if_rmap_get (const char *ifname
)
104 key
.ifname
= (char *)ifname
;
106 return (struct if_rmap
*) hash_get (ifrmaphash
, &key
, if_rmap_hash_alloc
);
110 if_rmap_hash_make (void *data
)
112 struct if_rmap
*if_rmap
= data
;
116 for (i
= 0; i
< strlen (if_rmap
->ifname
); i
++)
117 key
+= if_rmap
->ifname
[i
];
123 if_rmap_hash_cmp (const void *arg1
, const void* arg2
)
125 const struct if_rmap
*if_rmap1
= arg1
;
126 const struct if_rmap
*if_rmap2
= arg2
;
128 return strcmp (if_rmap1
->ifname
, if_rmap2
->ifname
) == 0;
131 static struct if_rmap
*
132 if_rmap_set (const char *ifname
, enum if_rmap_type type
,
133 const char *routemap_name
)
135 struct if_rmap
*if_rmap
;
137 if_rmap
= if_rmap_get (ifname
);
139 if (type
== IF_RMAP_IN
)
141 if (if_rmap
->routemap
[IF_RMAP_IN
])
142 XFREE (MTYPE_IF_RMAP_NAME
, if_rmap
->routemap
[IF_RMAP_IN
]);
143 if_rmap
->routemap
[IF_RMAP_IN
]
144 = XSTRDUP (MTYPE_IF_RMAP_NAME
, routemap_name
);
146 if (type
== IF_RMAP_OUT
)
148 if (if_rmap
->routemap
[IF_RMAP_OUT
])
149 XFREE (MTYPE_IF_RMAP_NAME
, if_rmap
->routemap
[IF_RMAP_OUT
]);
150 if_rmap
->routemap
[IF_RMAP_OUT
]
151 = XSTRDUP (MTYPE_IF_RMAP_NAME
, routemap_name
);
154 if (if_rmap_add_hook
)
155 (*if_rmap_add_hook
) (if_rmap
);
161 if_rmap_unset (const char *ifname
, enum if_rmap_type type
,
162 const char *routemap_name
)
164 struct if_rmap
*if_rmap
;
166 if_rmap
= if_rmap_lookup (ifname
);
170 if (type
== IF_RMAP_IN
)
172 if (!if_rmap
->routemap
[IF_RMAP_IN
])
174 if (strcmp (if_rmap
->routemap
[IF_RMAP_IN
], routemap_name
) != 0)
177 XFREE (MTYPE_IF_RMAP_NAME
, if_rmap
->routemap
[IF_RMAP_IN
]);
178 if_rmap
->routemap
[IF_RMAP_IN
] = NULL
;
181 if (type
== IF_RMAP_OUT
)
183 if (!if_rmap
->routemap
[IF_RMAP_OUT
])
185 if (strcmp (if_rmap
->routemap
[IF_RMAP_OUT
], routemap_name
) != 0)
188 XFREE (MTYPE_IF_RMAP_NAME
, if_rmap
->routemap
[IF_RMAP_OUT
]);
189 if_rmap
->routemap
[IF_RMAP_OUT
] = NULL
;
192 if (if_rmap_delete_hook
)
193 (*if_rmap_delete_hook
) (if_rmap
);
195 if (if_rmap
->routemap
[IF_RMAP_IN
] == NULL
&&
196 if_rmap
->routemap
[IF_RMAP_OUT
] == NULL
)
198 hash_release (ifrmaphash
, if_rmap
);
199 if_rmap_free (if_rmap
);
207 "route-map RMAP_NAME (in|out) IFNAME",
210 "Route map set for input filtering\n"
211 "Route map set for output filtering\n"
212 "Route map interface name\n")
214 enum if_rmap_type type
;
215 struct if_rmap
*if_rmap
;
217 if (strncmp (argv
[1], "i", 1) == 0)
219 else if (strncmp (argv
[1], "o", 1) == 0)
223 vty_out (vty
, "route-map direction must be [in|out]%s", VTY_NEWLINE
);
227 if_rmap
= if_rmap_set (argv
[2], type
, argv
[0]);
234 "route-map RMAP_NAME (in|out) IFNAME",
237 "Route map set for input filtering\n"
238 "Route map set for output filtering\n"
239 "Route map interface name\n")
243 "no route-map ROUTEMAP_NAME (in|out) IFNAME",
247 "Route map for input filtering\n"
248 "Route map for output filtering\n"
249 "Route map interface name\n")
252 enum if_rmap_type type
;
254 if (strncmp (argv
[1], "i", 1) == 0)
256 else if (strncmp (argv
[1], "o", 1) == 0)
260 vty_out (vty
, "route-map direction must be [in|out]%s", VTY_NEWLINE
);
264 ret
= if_rmap_unset (argv
[2], type
, argv
[0]);
267 vty_out (vty
, "route-map doesn't exist%s", VTY_NEWLINE
);
275 "no route-map ROUTEMAP_NAME (in|out) IFNAME",
279 "Route map for input filtering\n"
280 "Route map for output filtering\n"
281 "Route map interface name\n")
283 /* Configuration write function. */
285 config_write_if_rmap (struct vty
*vty
)
288 struct hash_backet
*mp
;
291 for (i
= 0; i
< ifrmaphash
->size
; i
++)
292 for (mp
= ifrmaphash
->index
[i
]; mp
; mp
= mp
->next
)
294 struct if_rmap
*if_rmap
;
298 if (if_rmap
->routemap
[IF_RMAP_IN
])
300 vty_out (vty
, " route-map %s in %s%s",
301 if_rmap
->routemap
[IF_RMAP_IN
],
307 if (if_rmap
->routemap
[IF_RMAP_OUT
])
309 vty_out (vty
, " route-map %s out %s%s",
310 if_rmap
->routemap
[IF_RMAP_OUT
],
322 hash_clean (ifrmaphash
, (void (*) (void *)) if_rmap_free
);
326 if_rmap_init (int node
)
328 ifrmaphash
= hash_create (if_rmap_hash_make
, if_rmap_hash_cmp
);
329 if (node
== RIPNG_NODE
) {
330 install_element (RIPNG_NODE
, &if_ipv6_rmap_cmd
);
331 install_element (RIPNG_NODE
, &no_if_ipv6_rmap_cmd
);
332 } else if (node
== RIP_NODE
) {
333 install_element (RIP_NODE
, &if_rmap_cmd
);
334 install_element (RIP_NODE
, &no_if_rmap_cmd
);