]>
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 (char *ifname
)
64 struct if_rmap
*if_rmap
;
68 if_rmap
= hash_lookup (ifrmaphash
, &key
);
74 if_rmap_hook_add (void (*func
) (struct if_rmap
*))
76 if_rmap_add_hook
= func
;
80 if_rmap_hook_delete (void (*func
) (struct if_rmap
*))
82 if_rmap_delete_hook
= func
;
86 if_rmap_hash_alloc (struct if_rmap
*arg
)
88 struct if_rmap
*if_rmap
;
90 if_rmap
= if_rmap_new ();
91 if_rmap
->ifname
= strdup (arg
->ifname
);
97 if_rmap_get (char *ifname
)
103 return (struct if_rmap
*) hash_get (ifrmaphash
, &key
, if_rmap_hash_alloc
);
107 if_rmap_hash_make (struct if_rmap
*if_rmap
)
113 for (i
= 0; i
< strlen (if_rmap
->ifname
); i
++)
114 key
+= if_rmap
->ifname
[i
];
120 if_rmap_hash_cmp (struct if_rmap
*if_rmap1
, struct if_rmap
*if_rmap2
)
122 if (strcmp (if_rmap1
->ifname
, if_rmap2
->ifname
) == 0)
128 if_rmap_set (char *ifname
, enum if_rmap_type type
, char *routemap_name
)
130 struct if_rmap
*if_rmap
;
132 if_rmap
= if_rmap_get (ifname
);
134 if (type
== IF_RMAP_IN
)
136 if (if_rmap
->routemap
[IF_RMAP_IN
])
137 free (if_rmap
->routemap
[IF_RMAP_IN
]);
138 if_rmap
->routemap
[IF_RMAP_IN
] = strdup (routemap_name
);
140 if (type
== IF_RMAP_OUT
)
142 if (if_rmap
->routemap
[IF_RMAP_OUT
])
143 free (if_rmap
->routemap
[IF_RMAP_OUT
]);
144 if_rmap
->routemap
[IF_RMAP_OUT
] = strdup (routemap_name
);
147 if (if_rmap_add_hook
)
148 (*if_rmap_add_hook
) (if_rmap
);
154 if_rmap_unset (char *ifname
, enum if_rmap_type type
, char *routemap_name
)
156 struct if_rmap
*if_rmap
;
158 if_rmap
= if_rmap_lookup (ifname
);
162 if (type
== IF_RMAP_IN
)
164 if (!if_rmap
->routemap
[IF_RMAP_IN
])
166 if (strcmp (if_rmap
->routemap
[IF_RMAP_IN
], routemap_name
) != 0)
169 free (if_rmap
->routemap
[IF_RMAP_IN
]);
170 if_rmap
->routemap
[IF_RMAP_IN
] = NULL
;
173 if (type
== IF_RMAP_OUT
)
175 if (!if_rmap
->routemap
[IF_RMAP_OUT
])
177 if (strcmp (if_rmap
->routemap
[IF_RMAP_OUT
], routemap_name
) != 0)
180 free (if_rmap
->routemap
[IF_RMAP_OUT
]);
181 if_rmap
->routemap
[IF_RMAP_OUT
] = NULL
;
184 if (if_rmap_delete_hook
)
185 (*if_rmap_delete_hook
) (if_rmap
);
187 if (if_rmap
->routemap
[IF_RMAP_IN
] == NULL
&&
188 if_rmap
->routemap
[IF_RMAP_OUT
] == NULL
)
190 hash_release (ifrmaphash
, if_rmap
);
191 if_rmap_free (if_rmap
);
199 "route-map RMAP_NAME (in|out) IFNAME",
202 "Route map set for input filtering\n"
203 "Route map set for output filtering\n"
204 "Route map interface name\n")
206 enum if_rmap_type type
;
207 struct if_rmap
*if_rmap
;
209 if (strncmp (argv
[1], "i", 1) == 0)
211 else if (strncmp (argv
[1], "o", 1) == 0)
215 vty_out (vty
, "route-map direction must be [in|out]%s", VTY_NEWLINE
);
219 if_rmap
= if_rmap_set (argv
[2], type
, argv
[0]);
226 "route-map RMAP_NAME (in|out) IFNAME",
229 "Route map set for input filtering\n"
230 "Route map set for output filtering\n"
231 "Route map interface name\n")
235 "no route-map ROUTEMAP_NAME (in|out) IFNAME",
239 "Route map for input filtering\n"
240 "Route map for output filtering\n"
241 "Route map interface name\n")
244 enum if_rmap_type type
;
246 if (strncmp (argv
[1], "i", 1) == 0)
248 else if (strncmp (argv
[1], "o", 1) == 0)
252 vty_out (vty
, "route-map direction must be [in|out]%s", VTY_NEWLINE
);
256 ret
= if_rmap_unset (argv
[2], type
, argv
[0]);
259 vty_out (vty
, "route-map doesn't exist%s", VTY_NEWLINE
);
267 "no route-map ROUTEMAP_NAME (in|out) IFNAME",
271 "Route map for input filtering\n"
272 "Route map for output filtering\n"
273 "Route map interface name\n")
275 /* Configuration write function. */
277 config_write_if_rmap (struct vty
*vty
)
280 struct hash_backet
*mp
;
283 for (i
= 0; i
< ifrmaphash
->size
; i
++)
284 for (mp
= ifrmaphash
->index
[i
]; mp
; mp
= mp
->next
)
286 struct if_rmap
*if_rmap
;
290 if (if_rmap
->routemap
[IF_RMAP_IN
])
292 vty_out (vty
, " route-map %s in %s%s",
293 if_rmap
->routemap
[IF_RMAP_IN
],
299 if (if_rmap
->routemap
[IF_RMAP_OUT
])
301 vty_out (vty
, " route-map %s out %s%s",
302 if_rmap
->routemap
[IF_RMAP_OUT
],
314 hash_clean (ifrmaphash
, (void (*) (void *)) if_rmap_free
);
318 if_rmap_init (int node
)
320 ifrmaphash
= hash_create (if_rmap_hash_make
, if_rmap_hash_cmp
);
321 if (node
== RIPNG_NODE
) {
322 install_element (RIPNG_NODE
, &if_ipv6_rmap_cmd
);
323 install_element (RIPNG_NODE
, &no_if_ipv6_rmap_cmd
);
324 } else if (node
== RIP_NODE
) {
325 install_element (RIP_NODE
, &if_rmap_cmd
);
326 install_element (RIP_NODE
, &no_if_rmap_cmd
);