Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | /********************************************************************************************************* |
| 2 | * Software License Agreement (BSD License) * |
| 3 | * Author: Francois Bard <francois@tera.ics.keio.ac.jp> * |
| 4 | * * |
| 5 | * Copyright (c) 2010, Teraoka Laboratory, Keio University * |
| 6 | * All rights reserved. * |
| 7 | * * |
| 8 | * Redistribution and use of this software in source and binary forms, with or without modification, are * |
| 9 | * permitted provided that the following conditions are met: * |
| 10 | * * |
| 11 | * * Redistributions of source code must retain the above * |
| 12 | * copyright notice, this list of conditions and the * |
| 13 | * following disclaimer. * |
| 14 | * * |
| 15 | * * Redistributions in binary form must reproduce the above * |
| 16 | * copyright notice, this list of conditions and the * |
| 17 | * following disclaimer in the documentation and/or other * |
| 18 | * materials provided with the distribution. * |
| 19 | * * |
| 20 | * * Neither the name of the Teraoka Laboratory nor the * |
| 21 | * names of its contributors may be used to endorse or * |
| 22 | * promote products derived from this software without * |
| 23 | * specific prior written permission of Teraoka Laboratory * |
| 24 | * * |
| 25 | * * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
| 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
| 28 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
| 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
| 30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
| 32 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
| 33 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
| 34 | *********************************************************************************************************/ |
| 35 | |
| 36 | /* |
| 37 | |
| 38 | The following table lists the AVPs needed for the NAS to HAAA server interaction. |
| 39 | We try to keep the structure of the grouped AVP by declaring the contained AVPs just before the grouped AVP they depend on. |
| 40 | The number of '+' indicates the depth of the contained AVP. |
| 41 | |
| 42 | DEPTH NAME AVP CODE RFC TYPE IMPLEMENTED NOTES |
| 43 | |
| 44 | MIP6-Feature-Vector 124 5447 Unsigned64 yes |
| 45 | + MIP-Home-Agent-Address 334 4004 Address not yet |
| 46 | ++ Destination-Host 293 3588 DiameterIdentity no (Base) |
| 47 | ++ Destination-Realm 283 3588 DiameterIdentity no (Base) |
| 48 | + MIP-Home-Agent-Host 348 4004 Grouped not yet |
| 49 | + MIP6-Home-Link-Prefix 125 5447 OctetString yes |
| 50 | MIP6-Agent-Info 486 5447 Grouped yes |
| 51 | |
| 52 | */ |
| 53 | |
| 54 | |
| 55 | |
| 56 | #include <freeDiameter/extension.h> |
| 57 | |
| 58 | /* The content of this file follows the same structure as dict_base_proto.c */ |
| 59 | |
| 60 | #define CHECK_dict_new( _type, _data, _parent, _ref ) \ |
| 61 | CHECK_FCT( fd_dict_new( fd_g_config->cnf_dict, (_type), (_data), (_parent), (_ref)) ); |
| 62 | |
| 63 | #define CHECK_dict_search( _type, _criteria, _what, _result ) \ |
| 64 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, (_type), (_criteria), (_what), (_result), ENOENT) ); |
| 65 | |
| 66 | struct local_rules_definition { |
| 67 | char *avp_name; |
| 68 | enum rule_position position; |
| 69 | int min; |
| 70 | int max; |
| 71 | }; |
| 72 | |
| 73 | #define RULE_ORDER( _position ) ((((_position) == RULE_FIXED_HEAD) || ((_position) == RULE_FIXED_TAIL)) ? 1 : 0 ) |
| 74 | |
| 75 | #define PARSE_loc_rules( _rulearray, _parent) { \ |
| 76 | int __ar; \ |
| 77 | for (__ar=0; __ar < sizeof(_rulearray) / sizeof((_rulearray)[0]); __ar++) { \ |
| 78 | struct dict_rule_data __data = { NULL, \ |
| 79 | (_rulearray)[__ar].position, \ |
| 80 | 0, \ |
| 81 | (_rulearray)[__ar].min, \ |
| 82 | (_rulearray)[__ar].max}; \ |
| 83 | __data.rule_order = RULE_ORDER(__data.rule_position); \ |
| 84 | CHECK_FCT( fd_dict_search( \ |
| 85 | fd_g_config->cnf_dict, \ |
| 86 | DICT_AVP, \ |
| 87 | AVP_BY_NAME, \ |
| 88 | (_rulearray)[__ar].avp_name, \ |
| 89 | &__data.rule_avp, 0 ) ); \ |
| 90 | if ( !__data.rule_avp ) { \ |
| 91 | TRACE_DEBUG(INFO, "AVP Not found: '%s'", (_rulearray)[__ar].avp_name ); \ |
| 92 | return ENOENT; \ |
| 93 | } \ |
| 94 | CHECK_FCT_DO( fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &__data, _parent, NULL), \ |
| 95 | { \ |
| 96 | TRACE_DEBUG(INFO, "Error on rule with AVP '%s'", \ |
| 97 | (_rulearray)[__ar].avp_name ); \ |
| 98 | return EINVAL; \ |
| 99 | } ); \ |
| 100 | } \ |
| 101 | } |
| 102 | |
| 103 | #define enumval_def_u32( _val_, _str_ ) \ |
| 104 | { _str_, { .u32 = _val_ }} |
| 105 | |
| 106 | #define enumval_def_os( _len_, _val_, _str_ ) \ |
| 107 | { _str_, { .os = { .data = (unsigned char *)_val_, .len = _len_ }}} |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | /* Defines if there are any */ |
| 115 | |
| 116 | /* Define Flags for MIP6-Feature-Vector*/ |
| 117 | |
| 118 | #define MIP6_INTEGRATED 0x0000000000000001 |
| 119 | #define LOCAL_HOME_AGENT_ASSIGNMENT 0x0000000000000002 |
| 120 | |
| 121 | /* Dictionary */ |
| 122 | |
| 123 | int dict_nas_mipv6_init(char * conffile) |
| 124 | { |
| 125 | struct dict_object * nas_mipv6; |
| 126 | { |
| 127 | struct dict_application_data data = { 5447, "MIPv6 NAS-to-HAAA Interaction" }; |
| 128 | CHECK_dict_new( DICT_APPLICATION, &data , NULL, &nas_mipv6); |
| 129 | } |
| 130 | |
| 131 | /* AVP section */ |
| 132 | { |
| 133 | /* Loading the derived data formats */ |
| 134 | |
| 135 | struct dict_object * Address_type; |
| 136 | CHECK_dict_search( DICT_TYPE, TYPE_BY_NAME, "Address", &Address_type); |
| 137 | |
| 138 | /* MIP6-Feature-Vector */ |
| 139 | { |
| 140 | /* |
| 141 | |
| 142 | */ |
| 143 | |
| 144 | struct dict_avp_data data = { |
| 145 | 124, /* Code */ |
| 146 | 0, /* Vendor */ |
| 147 | "MIP6-Feature-Vector", /* Name */ |
| 148 | AVP_FLAG_VENDOR | AVP_FLAG_MANDATORY, /* Fixed flags */ |
| 149 | AVP_FLAG_MANDATORY, /* Fixed flag values */ |
| 150 | AVP_TYPE_UNSIGNED64 /* base type of data */ |
| 151 | }; |
| 152 | |
| 153 | CHECK_dict_new( DICT_AVP, &data , NULL, NULL); |
| 154 | } |
| 155 | |
| 156 | /* MIP-Home-Agent-Address - RFC 4004 */ |
| 157 | { |
| 158 | /* |
| 159 | |
| 160 | */ |
| 161 | |
| 162 | struct dict_avp_data data = { |
| 163 | 334, /* Code */ |
| 164 | 0, /* Vendor */ |
| 165 | "MIP-Home-Agent-Address", /* Name */ |
| 166 | AVP_FLAG_VENDOR | AVP_FLAG_MANDATORY, /* Fixed flags */ |
| 167 | AVP_FLAG_MANDATORY, /* Fixed flag values */ |
| 168 | AVP_TYPE_OCTETSTRING /* base type of data */ |
| 169 | }; |
| 170 | |
| 171 | CHECK_dict_new( DICT_AVP, &data , Address_type, NULL); |
| 172 | } |
| 173 | |
| 174 | /* Destination-Host - Base Protocol */ |
| 175 | |
| 176 | /* Destination-Realm - Base Protocol */ |
| 177 | |
| 178 | /* MIP-Home-Agent-Host - RFC 4004 */ |
| 179 | { |
| 180 | /* |
| 181 | The MIP-Home-Agent-Host AVP (AVP Code 348) is of type Grouped and |
| 182 | contains the identity of the assigned Home Agent. If the MIP-Home- |
| 183 | Agent-Host AVP is present in the AMR, the AAAH MUST copy it into the |
| 184 | HAR. |
| 185 | |
| 186 | MIP-Home-Agent-Host ::= < AVP Header: 348 > |
| 187 | { Destination-Realm } |
| 188 | { Destination-Host } |
| 189 | * [ AVP ] |
| 190 | */ |
| 191 | |
| 192 | struct dict_object * avp; |
| 193 | struct dict_avp_data data = { |
| 194 | 348, /* Code */ |
| 195 | 0, /* Vendor */ |
| 196 | "MIP-Home-Agent-Host", /* Name */ |
| 197 | AVP_FLAG_VENDOR | AVP_FLAG_MANDATORY, /* Fixed flags */ |
| 198 | AVP_FLAG_MANDATORY, /* Fixed flag values */ |
| 199 | AVP_TYPE_GROUPED /* base type of data */ |
| 200 | }; |
| 201 | |
| 202 | struct local_rules_definition rules[] = |
| 203 | { { "Destination-Realm", RULE_REQUIRED, -1, 1 } |
| 204 | ,{ "Destination-Host", RULE_REQUIRED, -1, 1 } |
| 205 | }; |
| 206 | |
| 207 | CHECK_dict_new( DICT_AVP, &data , NULL, &avp); |
| 208 | PARSE_loc_rules( rules, avp ); |
| 209 | } |
| 210 | |
| 211 | /* MIP6-Home-Link-Prefix */ |
| 212 | { |
| 213 | /* |
| 214 | |
| 215 | */ |
| 216 | |
| 217 | struct dict_avp_data data = { |
| 218 | 125, /* Code */ |
| 219 | 0, /* Vendor */ |
| 220 | "MIP6-Home-Link-Prefix", /* Name */ |
| 221 | AVP_FLAG_VENDOR | AVP_FLAG_MANDATORY, /* Fixed flags */ |
| 222 | AVP_FLAG_MANDATORY, /* Fixed flag values */ |
| 223 | AVP_TYPE_OCTETSTRING /* base type of data */ |
| 224 | }; |
| 225 | |
| 226 | CHECK_dict_new( DICT_AVP, &data , NULL, NULL); |
| 227 | } |
| 228 | |
| 229 | /* MIP6-Agent-Info */ |
| 230 | { |
| 231 | /* |
| 232 | |
| 233 | */ |
| 234 | struct dict_object * avp; |
| 235 | struct dict_avp_data data = { |
| 236 | 486, /* Code */ |
| 237 | 0, /* Vendor */ |
| 238 | "MIP6-Agent-Info", /* Name */ |
| 239 | AVP_FLAG_VENDOR | AVP_FLAG_MANDATORY, /* Fixed flags */ |
| 240 | AVP_FLAG_MANDATORY, /* Fixed flag values */ |
| 241 | AVP_TYPE_GROUPED /* base type of data */ |
| 242 | }; |
| 243 | |
| 244 | struct local_rules_definition rules[] = |
| 245 | { { "MIP-Home-Agent-Address", RULE_OPTIONAL, -1, 2 } |
| 246 | ,{ "MIP-Home-Agent-Host", RULE_OPTIONAL, -1, 1 } |
| 247 | ,{ "MIP6-Home-Link-Prefix", RULE_OPTIONAL, -1, 1 } |
| 248 | }; |
| 249 | |
| 250 | CHECK_dict_new( DICT_AVP, &data , NULL, &avp); |
| 251 | PARSE_loc_rules( rules, avp ); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | LOG_D( "Dictionary Extension 'MIPv6 NAS-to-HAAA Interaction' initialized"); |
| 256 | return 0; |
| 257 | } |
| 258 | EXTENSION_ENTRY("dict_nas_mipv6", dict_nas_mipv6_init); |