Home | History | Annotate | Download | only in route
      1 /*
      2  * lib/route/cls_api.c       Classifier Module API
      3  *
      4  *	This library is free software; you can redistribute it and/or
      5  *	modify it under the terms of the GNU Lesser General Public
      6  *	License as published by the Free Software Foundation version 2.1
      7  *	of the License.
      8  *
      9  * Copyright (c) 2003-2008 Thomas Graf <tgraf (at) suug.ch>
     10  */
     11 
     12 /**
     13  * @ingroup cls
     14  * @defgroup cls_api Classifier Modules
     15  * @{
     16  */
     17 
     18 #include <netlink-local.h>
     19 #include <netlink-tc.h>
     20 #include <netlink/netlink.h>
     21 #include <netlink/utils.h>
     22 #include <netlink/route/tc.h>
     23 #include <netlink/route/classifier.h>
     24 #include <netlink/route/classifier-modules.h>
     25 #include <netlink/route/link.h>
     26 
     27 static struct rtnl_cls_ops *cls_ops_list;
     28 
     29 /**
     30  * @name Classifier Module API
     31  * @{
     32  */
     33 
     34 /**
     35  * Register a classifier module
     36  * @arg cops		classifier module operations
     37  */
     38 int rtnl_cls_register(struct rtnl_cls_ops *cops)
     39 {
     40 	struct rtnl_cls_ops *o, **op;
     41 
     42 	if (!cops->co_kind)
     43 		BUG();
     44 
     45 	for (op = &cls_ops_list; (o = *op) != NULL; op = &o->co_next)
     46 		if (!strcasecmp(cops->co_kind, o->co_kind))
     47 			return -NLE_EXIST;
     48 
     49 	cops->co_next = NULL;
     50 	*op = cops;
     51 
     52 	return 0;
     53 }
     54 
     55 /**
     56  * Unregister a classifier module
     57  * @arg cops		classifier module operations
     58  */
     59 int rtnl_cls_unregister(struct rtnl_cls_ops *cops)
     60 {
     61 	struct rtnl_cls_ops *o, **op;
     62 
     63 	for (op = &cls_ops_list; (o = *op) != NULL; op = &o->co_next)
     64 		if (!strcasecmp(cops->co_kind, o->co_kind))
     65 			break;
     66 
     67 	if (!o)
     68 		return -NLE_OBJ_NOTFOUND;
     69 
     70 	*op = cops->co_next;
     71 
     72 	return 0;
     73 }
     74 
     75 struct rtnl_cls_ops *__rtnl_cls_lookup_ops(const char *kind)
     76 {
     77 	struct rtnl_cls_ops *cops;
     78 
     79 	for (cops = cls_ops_list; cops; cops = cops->co_next)
     80 		if (!strcmp(kind, cops->co_kind))
     81 			return cops;
     82 
     83 	return NULL;
     84 }
     85 
     86 /**
     87  * Lookup classifier operations for a classifier object
     88  * @arg cls		Classifier object.
     89  *
     90  * @return Classifier operations or NULL if not found.
     91  */
     92 struct rtnl_cls_ops *rtnl_cls_lookup_ops(struct rtnl_cls *cls)
     93 {
     94 	if (!cls->c_ops)
     95 		cls->c_ops = __rtnl_cls_lookup_ops(cls->c_kind);
     96 
     97 	return cls->c_ops;
     98 }
     99 
    100 
    101 /** @} */
    102 
    103 /** @} */
    104