[mpls-linux-general] [PATCH 1/2] mpls-mpls_if.c-cleanup-comment.diff
Status: Beta
Brought to you by:
jleu
|
From: Ramon C. <cas...@in...> - 2003-11-19 22:49:24
|
James/All, Attached patch: mpls-mpls_if.c-cleanup-comment.diff * mpls_if.c : clean up, format and comment. Nothing big. Remark: * This patch and the one that follows should apply nicely to your p4 depot. Synced today (although I'll talk to you in private email, since your depot eat my disk space :) for kernel 2.6.0-test9 * Since your p4 version does not (yet) compile, I cannot test it. For this early stages (for me at least), I would really like you to "peer-review" them. // ------------------------------------------------------------------- // Ramon Casellas - GET/ENST/INFRES/RHD/A508 - cas...@in... // 37/39 rue Dareau 75014 Paris -- http://perso.enst.fr/~casellas 8<-----8<-------8< diff -urN mpls/mpls_if.c mpls.rcas/mpls_if.c --- mpls/mpls_if.c 2003-11-19 14:17:48.000000000 +0100 +++ mpls.rcas/mpls_if.c 2003-11-19 23:24:12.307079184 +0100 @@ -1,91 +1,149 @@ -/* - * MPLS An implementation of MPLS forwarding for the Linux Kernel. - * MPLS is implemented based off of the IETF drafts: - * -draft-ietf-mpls-arch-06 - * -draft-ietf-mpls-framework-05 - * -draft-ietf-mpls-label-encaps-07 - * - * It implements: - * -interface specific settings for MPLS - * - * Authors: James R. Leu, <jl...@mi...> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version - * 2 of the License, or (at your option) any later version. +/***************************************************************************** + * MPLS + * An implementation of the MPLS (MultiProtocol Label + * Switching) Architecture for Linux. * + * __THIS_FILE__ + * * Allocation/Deallocation of per netdevice MPLS private data + * (labelspace) + * * Query/Update netdevice label space functions. + * + * $Id$ + * + * Authors: + * James Leu <jl...@mi...> + * Ramon Casellas <cas...@in...> + * + * (c) 1999-2003 James Leu <jl...@mi...> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * $ChangeLog$ + ***************************************************************************** */ #include <asm/uaccess.h> #include <linux/netdevice.h> #include <net/mpls.h> -int mpls_get_labelspace(struct mpls_labelspace_req *req) { - const char *fn_name = "mpls_get_labelspace"; - struct net_device *dev; - int result = -1; - - MPLS_DEBUG(("%s: enter\n",fn_name)); - if(req) { - dev = dev_get_by_index(req->mls_ifindex); - if(dev) { - if (dev->mpls_ptr) { - req->mls_labelspace = - ((struct mpls_interface*)(dev->mpls_ptr))->labelspace; - } else { - req->mls_labelspace = -1; - } - result = 0; - dev_put(dev); - } - } - MPLS_DEBUG(("%s: exit\n",fn_name)); - return result; + + +/**** + * mpls_create_if_info - allocate memory for the MPLS net_device extension + * + * Returns a pointer to the allocated struct. + ***/ + + +struct mpls_interface *mpls_create_if_info(void) +{ + struct mpls_interface *mpls_if = NULL; + + mpls_if = + (struct mpls_interface *) + kmalloc(sizeof(struct mpls_interface), GFP_ATOMIC); + if (NULL == mpls_if) + return NULL; + + memset(mpls_if, 0, sizeof(struct mpls_interface)); + mpls_if->labelspace = -1; + INIT_LIST_HEAD(&(mpls_if->list_out)); + INIT_LIST_HEAD(&(mpls_if->list_in)); + return mpls_if; } -void *mpls_create_if_info(void) { - struct mpls_interface *mpls_if; - mpls_if = (struct mpls_interface*)kmalloc(sizeof(struct mpls_interface), - GFP_ATOMIC); - memset(mpls_if,0,sizeof(*mpls_if)); - mpls_if->labelspace = -1; - INIT_LIST_HEAD(&mpls_if->list_out); - INIT_LIST_HEAD(&mpls_if->list_in); - return (void*)mpls_if; + + + +/**** + * mpls_delete_if_info - free memory for the MPLS net_device extension + * + * Deallocation of MPLS netdev extensions. + * + ***/ + +void mpls_delete_if_info(struct mpls_interface *mpls_if) +{ + kfree(mpls_if); } -void mpls_delete_if_info(struct mpls_interface* mpls_if) { - kfree(mpls_if); + + + +/**** + * mpls_get_labelspace - Get the label space for the interface + * + * @req: mpls_labelspace_req struct with the query data. In particular, + * contains the interface index in req->mls_ifindex. + * + * Returns 0 on sucess and sets the label space for the netdevice in + * req->mls_ifindex. The labelspace in req->mls_ifindex may be -1 if MPLS + * was not active on the interface. + ***/ + +int mpls_get_labelspace(struct mpls_labelspace_req *req) +{ + struct net_device *dev = NULL; + struct mpls_interface *mpls_ptr = NULL; + BUG_ON(NULL == req); + + dev = dev_get_by_index(req->mls_ifindex); + if (NULL == dev) { + return -1; + } + + mpls_ptr = (struct mpls_interface *) dev->mpls_ptr; + req->mls_labelspace = (mpls_ptr) ? mpls_ptr->labelspace : -1; + dev_put(dev); + return 0; } -int mpls_set_labelspace(struct mpls_labelspace_req *req) { - const char *fn_name = "mpls_set_labelspace"; - struct net_device *dev; - int result = -1; - - MPLS_DEBUG(("%s: enter\n",fn_name)); - if(req) { - MPLS_DEBUG(("%s: labelspace(%d)\n",fn_name,req->mls_labelspace)); - if((dev = dev_get_by_index(req->mls_ifindex))) { - if (!dev->mpls_ptr) { - dev->mpls_ptr = mpls_create_if_info(); - if (!dev->mpls_ptr) { - dev_put(dev); - return -ENOMEM; - } - } - if (req->mls_labelspace == -1) { - mpls_delete_if_info(dev->mpls_ptr); - dev->mpls_ptr = NULL; - } else { - ((struct mpls_interface*)(dev->mpls_ptr))->labelspace = - req->mls_labelspace; - } - result = 0; - dev_put(dev); - } - } - MPLS_DEBUG(("%s: exit\n",fn_name)); - return result; + + +/**** + * mpls_set_labelspace - Set a label space for the interface. + * + * @req: mpls_labelspace_req struct with the update data. In particular, + * contains the interface index in req->mls_ifindex, and the new + * labelspace in req->mls_labelspace. + * + * This function assigns a label space to a particular net device. In + * the current implementation, the netdev struct is extended with a + * mpls_ptr to hold mpls data, which is dynamically allocated here, + * using mpls_create_if_info(). + * + * Returns 0 on success. + ***/ + +int mpls_set_labelspace(struct mpls_labelspace_req *req) +{ + const char *fn_name = "mpls_set_labelspace"; + struct net_device *dev = NULL; + struct mpls_interface *mpls_ptr = NULL; + BUG_ON(NULL == req); + + dev = dev_get_by_index(req->mls_ifindex); + if (NULL == dev) + return -1; + + if ((!dev->mpls_ptr) && (req->mls_labelspace != -1)) { + dev->mpls_ptr = (void *) mpls_create_if_info(); + if (!dev->mpls_ptr) { + dev_put(dev); + return -ENOMEM; + } + /* Actual assignment happens here */ + mpls_ptr = (struct mpls_interface *) dev->mpls_ptr; + mpls_ptr->labelspace = req->mls_labelspace; + } + + if ((-1 == req->mls_labelspace) && (dev->mpls_ptr)) { + mpls_delete_if_info(dev->mpls_ptr); + dev->mpls_ptr = NULL; + } + dev_put(dev); + return 0; } |