/build/buildd/libnl-1.0~pre6/lib/route/rtnl.c

00001 /*
00002  * lib/route/rtnl.c             Routing Netlink
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 /**
00013  * @defgroup rtnl Routing Netlink
00014  * @{
00015  */
00016 
00017 #include <netlink-local.h>
00018 #include <netlink/netlink.h>
00019 #include <netlink/utils.h>
00020 #include <netlink/route/rtnl.h>
00021 
00022 /**
00023  * @name Sending
00024  * @{
00025  */
00026 
00027 /**
00028  * Send routing netlink request message
00029  * @arg handle          Netlink handle.
00030  * @arg type            Netlink message type.
00031  * @arg family          Address family.
00032  * @arg flags           Additional netlink message flags.
00033  *
00034  * Fills out a routing netlink request message and sends it out
00035  * using nl_send_simple().
00036  *
00037  * @return 0 on success or a negative error code.
00038  */
00039 int nl_rtgen_request(struct nl_handle *handle, int type, int family, int flags)
00040 {
00041         struct rtgenmsg gmsg = {
00042                 .rtgen_family = family,
00043         };
00044 
00045         return nl_send_simple(handle, type, flags, &gmsg, sizeof(gmsg));
00046 }
00047 
00048 /** @} */
00049 
00050 /**
00051  * @name Routing Type Translations
00052  * @{
00053  */
00054 
00055 static struct trans_tbl rtntypes[] = {
00056         __ADD(RTN_UNSPEC,unspec)
00057         __ADD(RTN_UNICAST,unicast)
00058         __ADD(RTN_LOCAL,local)
00059         __ADD(RTN_BROADCAST,broadcast)
00060         __ADD(RTN_ANYCAST,anycast)
00061         __ADD(RTN_MULTICAST,multicast)
00062         __ADD(RTN_BLACKHOLE,blackhole)
00063         __ADD(RTN_UNREACHABLE,unreachable)
00064         __ADD(RTN_PROHIBIT,prohibit)
00065         __ADD(RTN_THROW,throw)
00066         __ADD(RTN_NAT,nat)
00067         __ADD(RTN_XRESOLVE,xresolve)
00068 };
00069 
00070 /**
00071  * Convert routing type to character string.
00072  * @arg type            Routing type.
00073  * @arg buf             Destination buffer.
00074  * @arg size            Size of destination buffer.
00075  *
00076  * Converts a routing type to a character string and stores it in
00077  * the specified destination buffer.
00078  *
00079  * @return The destination buffer or the type encoded in hexidecimal
00080  *         form if the routing type is unknown.
00081  */
00082 char *nl_rtntype2str(int type, char *buf, size_t size)
00083 {
00084         return __type2str(type, buf, size, rtntypes, ARRAY_SIZE(rtntypes));
00085 }
00086 
00087 /**
00088  * Convert character string to routing type.
00089  * @arg name            Name of routing type.
00090  *
00091  * Converts the provided character string specifying a routing
00092  * type to the corresponding numeric value.
00093  *
00094  * @return Routing type or a negative value if no match was found.
00095  */
00096 int nl_str2rtntype(const char *name)
00097 {
00098         return __str2type(name, rtntypes, ARRAY_SIZE(rtntypes));
00099 }
00100 
00101 /** @} */
00102 
00103 /**
00104  * @name Scope Translations
00105  * @{
00106  */
00107 
00108 static struct trans_tbl scopes[] = {
00109         __ADD(255,nowhere)
00110         __ADD(254,host)
00111         __ADD(253,link)
00112         __ADD(200,site)
00113         __ADD(0,global)
00114 };
00115 
00116 /**
00117  * Convert scope identifier to character string.
00118  * @arg scope           Scope identifier.
00119  * @arg buf             Destination buffer
00120  * @arg size            Size of destination buffer.
00121  *
00122  * Converts a scope identifier to a character string and stores it in
00123  * the specified destination buffer.
00124  *
00125  * @return The destination buffer or the type encoded in hexidecimal
00126  *         form if the scope identifier is unknown.
00127  */
00128 char *rtnl_scope2str(int scope, char *buf, size_t size)
00129 {
00130         return __type2str(scope, buf, size, scopes, ARRAY_SIZE(scopes));
00131 }
00132 
00133 /**
00134  * Convert character string to scope identifier.
00135  * @arg name            Name of scope.
00136  *
00137  * Converts the provided character string specifying a scope identifier
00138  * to the corresponding numeric value.
00139  *
00140  * @return Scope identifier or a negative value if no match was found.
00141  */
00142 int rtnl_str2scope(const char *name)
00143 {
00144         return __str2type(name, scopes, ARRAY_SIZE(scopes));
00145 }
00146 
00147 /** @} */
00148 
00149 /**
00150  * @name Realms Translations
00151  * @{
00152  */
00153 
00154 char * rtnl_realms2str(uint32_t realms, char *buf, size_t len)
00155 {
00156         int from = RTNL_REALM_FROM(realms);
00157         int to = RTNL_REALM_TO(realms);
00158 
00159         snprintf(buf, len, "%d/%d", from, to);
00160 
00161         return buf;
00162 }
00163 
00164 /** @} */
00165 
00166 
00167 
00168 /** @} */

Generated on Fri Apr 27 14:14:07 2007 for libnl by  doxygen 1.5.1