]>
git.proxmox.com Git - mirror_frr.git/blob - lib/if_rmap.c
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 void (*if_rmap_add_hook
) (struct if_rmap
*) = NULL
;
34 void (*if_rmap_delete_hook
) (struct if_rmap
*) = NULL
;
41 new = XCALLOC (MTYPE_IF_RMAP
, sizeof (struct if_rmap
));
47 if_rmap_free (struct if_rmap
*if_rmap
)
50 free (if_rmap
->ifname
);
52 if (if_rmap
->routemap
[IF_RMAP_IN
])
53 free (if_rmap
->routemap
[IF_RMAP_IN
]);
54 if (if_rmap
->routemap
[IF_RMAP_OUT
])
55 free (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 (struct if_rmap
*arg
)
89 struct if_rmap
*if_rmap
;
91 if_rmap
= if_rmap_new ();
92 if_rmap
->ifname
= strdup (arg
->ifname
);
98 if_rmap_get (const char *ifname
)
103 key
.ifname
= (char *)ifname
;
105 return (struct if_rmap
*) hash_get (ifrmaphash
, &key
, if_rmap_hash_alloc
);
109 if_rmap_hash_make (struct if_rmap
*if_rmap
)
114 for (i
= 0; i
< strlen (if_rmap
->ifname
); i
++)
115 key
+= if_rmap
->ifname
[i
];
121 if_rmap_hash_cmp (struct if_rmap
*if_rmap1
, struct if_rmap
*if_rmap2
)
123 if (strcmp (if_rmap1
->ifname
, if_rmap2
->ifname
) == 0)
129 if_rmap_set (const char *ifname
, enum if_rmap_type type
,
130 const char *routemap_name
)
132 struct if_rmap
*if_rmap
;
134 if_rmap
= if_rmap_get (ifname
);
136 if (type
== IF_RMAP_IN
)
138 if (if_rmap
->routemap
[IF_RMAP_IN
])
139 free (if_rmap
->routemap
[IF_RMAP_IN
]);
140 if_rmap
->routemap
[IF_RMAP_IN
] = strdup (routemap_name
);
142 if (type
== IF_RMAP_OUT
)
144 if (if_rmap
->routemap
[IF_RMAP_OUT
])
145 free (if_rmap
->routemap
[IF_RMAP_OUT
]);
146 if_rmap
->routemap
[IF_RMAP_OUT
] = strdup (routemap_name
);
149 if (if_rmap_add_hook
)
150 (*if_rmap_add_hook
) (if_rmap
);
156 if_rmap_unset (const char *ifname
, enum if_rmap_type type
,
157 const char *routemap_name
)
159 struct if_rmap
*if_rmap
;
161 if_rmap
= if_rmap_lookup (ifname
);
165 if (type
== IF_RMAP_IN
)
167 if (!if_rmap
->routemap
[IF_RMAP_IN
])
169 if (strcmp (if_rmap
->routemap
[IF_RMAP_IN
], routemap_name
) != 0)
172 free (if_rmap
->routemap
[IF_RMAP_IN
]);
173 if_rmap
->routemap
[IF_RMAP_IN
] = NULL
;
176 if (type
== IF_RMAP_OUT
)
178 if (!if_rmap
->routemap
[IF_RMAP_OUT
])
180 if (strcmp (if_rmap
->routemap
[IF_RMAP_OUT
], routemap_name
) != 0)
183 free (if_rmap
->routemap
[IF_RMAP_OUT
]);
184 if_rmap
->routemap
[IF_RMAP_OUT
] = NULL
;
187 if (if_rmap_delete_hook
)
188 (*if_rmap_delete_hook
) (if_rmap
);
190 if (if_rmap
->routemap
[IF_RMAP_IN
] == NULL
&&
191 if_rmap
->routemap
[IF_RMAP_OUT
] == NULL
)
193 hash_release (ifrmaphash
, if_rmap
);
194 if_rmap_free (if_rmap
);
202 "route-map RMAP_NAME (in|out) IFNAME",
205 "Route map set for input filtering\n"
206 "Route map set for output filtering\n"
207 "Route map interface name\n")
209 enum if_rmap_type type
;
210 struct if_rmap
*if_rmap
;
212 if (strncmp (argv
[1], "i", 1) == 0)
214 else if (strncmp (argv
[1], "o", 1) == 0)
218 vty_out (vty
, "route-map direction must be [in|out]%s", VTY_NEWLINE
);
222 if_rmap
= if_rmap_set (argv
[2], type
, argv
[0]);
229 "route-map RMAP_NAME (in|out) IFNAME",
232 "Route map set for input filtering\n"
233 "Route map set for output filtering\n"
234 "Route map interface name\n")
238 "no route-map ROUTEMAP_NAME (in|out) IFNAME",
242 "Route map for input filtering\n"
243 "Route map for output filtering\n"
244 "Route map interface name\n")
247 enum if_rmap_type type
;
249 if (strncmp (argv
[1], "i", 1) == 0)
251 else if (strncmp (argv
[1], "o", 1) == 0)
255 vty_out (vty
, "route-map direction must be [in|out]%s", VTY_NEWLINE
);
259 ret
= if_rmap_unset (argv
[2], type
, argv
[0]);
262 vty_out (vty
, "route-map doesn't exist%s", VTY_NEWLINE
);
270 "no route-map ROUTEMAP_NAME (in|out) IFNAME",
274 "Route map for input filtering\n"
275 "Route map for output filtering\n"
276 "Route map interface name\n")
278 /* Configuration write function. */
280 config_write_if_rmap (struct vty
*vty
)
283 struct hash_backet
*mp
;
286 for (i
= 0; i
< ifrmaphash
->size
; i
++)
287 for (mp
= ifrmaphash
->index
[i
]; mp
; mp
= mp
->next
)
289 struct if_rmap
*if_rmap
;
293 if (if_rmap
->routemap
[IF_RMAP_IN
])
295 vty_out (vty
, " route-map %s in %s%s",
296 if_rmap
->routemap
[IF_RMAP_IN
],
302 if (if_rmap
->routemap
[IF_RMAP_OUT
])
304 vty_out (vty
, " route-map %s out %s%s",
305 if_rmap
->routemap
[IF_RMAP_OUT
],
317 hash_clean (ifrmaphash
, (void (*) (void *)) if_rmap_free
);
321 if_rmap_init (int node
)
323 ifrmaphash
= hash_create (if_rmap_hash_make
, if_rmap_hash_cmp
);
324 if (node
== RIPNG_NODE
) {
325 install_element (RIPNG_NODE
, &if_ipv6_rmap_cmd
);
326 install_element (RIPNG_NODE
, &no_if_ipv6_rmap_cmd
);
327 } else if (node
== RIP_NODE
) {
328 install_element (RIP_NODE
, &if_rmap_cmd
);
329 install_element (RIP_NODE
, &no_if_rmap_cmd
);