Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/ipp/ipgpc/classifierddi.c
+++ new/usr/src/uts/common/ipp/ipgpc/classifierddi.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/systm.h>
27 27 #include <sys/socket.h>
28 28 #include <netinet/in.h>
29 29 #include <sys/modctl.h>
30 30 #include <sys/sunddi.h>
31 31 #include <ipp/ipp.h>
32 32 #include <ipp/ipp_config.h>
33 33 #include <ipp/ipgpc/classifier.h>
34 34 #include <inet/ip.h>
35 35 #include <net/if.h>
36 36 #include <inet/ip_if.h>
37 37 #include <inet/ipp_common.h>
38 38
39 39 /* DDI file for ipgpc ipp module */
40 40
41 41 /* protects against multiple configs */
42 42 static kmutex_t ipgpc_config_lock;
43 43
44 44 static int ipgpc_create_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
45 45 static int ipgpc_modify_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
46 46 static int ipgpc_destroy_action(ipp_action_id_t, ipp_flags_t);
47 47 static int ipgpc_info(ipp_action_id_t aid, int (*)(nvlist_t *, void *), void *,
48 48 ipp_flags_t);
49 49 static int ipgpc_invoke_action(ipp_action_id_t, ipp_packet_t *);
50 50
51 51 ipp_ops_t ipgpc_ops = {
52 52 IPPO_REV,
53 53 ipgpc_create_action, /* ippo_action_create */
54 54 ipgpc_modify_action, /* ippo_action_modify */
55 55 ipgpc_destroy_action, /* ippo_action_destroy */
56 56 ipgpc_info, /* ippo_action_info */
57 57 ipgpc_invoke_action /* ippo_action_invoke */
58 58 };
59 59
60 60 extern struct mod_ops mod_ippops;
61 61
62 62 /*
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
63 63 * Module linkage information for the kernel.
64 64 */
65 65 static struct modlipp modlipp = {
66 66 &mod_ippops,
67 67 "IP Generic Packet Classifier (ipgpc) module 1.0",
68 68 &ipgpc_ops
69 69 };
70 70
71 71 static struct modlinkage modlinkage = {
72 72 MODREV_1,
73 - (void *)&modlipp,
74 - NULL
73 + { (void *)&modlipp, NULL }
75 74 };
76 75
77 76 #define __FN__ "_init"
78 77 int
79 78 _init(
80 79 void)
81 80 {
82 81 int rc;
83 82
84 83 if (ipgpc_action_exist) {
85 84 return (EBUSY);
86 85 }
87 86 /* init mutexes */
88 87 mutex_init(&ipgpc_config_lock, NULL, MUTEX_DRIVER, NULL);
89 88 mutex_init(&ipgpc_fid_list_lock, NULL, MUTEX_DRIVER, NULL);
90 89 mutex_init(&ipgpc_cid_list_lock, NULL, MUTEX_DRIVER, NULL);
91 90 mutex_init(&ipgpc_table_list_lock, NULL, MUTEX_DRIVER, NULL);
92 91 mutex_init(&ipgpc_ds_table_id.lock, NULL, MUTEX_DRIVER, NULL);
93 92
94 93 if ((rc = mod_install(&modlinkage)) != 0) {
95 94 /* clean up after fail */
96 95 mutex_destroy(&ipgpc_config_lock);
97 96 mutex_destroy(&ipgpc_fid_list_lock);
98 97 mutex_destroy(&ipgpc_cid_list_lock);
99 98 mutex_destroy(&ipgpc_table_list_lock);
100 99 mutex_destroy(&ipgpc_ds_table_id.lock);
101 100 }
102 101
103 102 return (rc);
104 103 }
105 104 #undef __FN__
106 105
107 106 #define __FN__ "_fini"
108 107 int
109 108 _fini(
110 109 void)
111 110 {
112 111 int rc;
113 112
114 113 if (ipgpc_action_exist) {
115 114 return (EBUSY);
116 115 }
117 116
118 117 if ((rc = mod_remove(&modlinkage)) != 0) {
119 118 return (rc);
120 119 }
121 120 /* destroy mutexes */
122 121 mutex_destroy(&ipgpc_config_lock);
123 122 mutex_destroy(&ipgpc_fid_list_lock);
124 123 mutex_destroy(&ipgpc_cid_list_lock);
125 124 mutex_destroy(&ipgpc_table_list_lock);
126 125 mutex_destroy(&ipgpc_ds_table_id.lock);
127 126 return (rc);
128 127 }
129 128 #undef __FN__
130 129
131 130 #define __FN__ "_info"
132 131 int
133 132 _info(
134 133 struct modinfo *modinfop)
135 134 {
136 135 return (mod_info(&modlinkage, modinfop));
137 136 }
138 137 #undef __FN__
139 138
140 139 /*
141 140 * ipgpc_create_action(aid, nvlpp, flags)
142 141 *
143 142 * creates a single instance of ipgpc, if one does not exist. If an action
144 143 * instance already exists, fail with EBUSY
145 144 *
146 145 * if nvlpp contains the name IPP_ACTION_STATS_ENABLE, then process it and
147 146 * determine if global stats should be collected
148 147 *
149 148 * the ipgpc_config_lock is taken to block out any other creates or destroys
150 149 * the are issued while the create is taking place
151 150 */
152 151 /* ARGSUSED */
153 152 static int
154 153 ipgpc_create_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
155 154 {
156 155 int rc;
157 156 uint32_t stat;
158 157 nvlist_t *nvlp;
159 158
160 159 nvlp = *nvlpp;
161 160 *nvlpp = NULL; /* nvlist should be NULL when this returns */
162 161
163 162 /* only one ipgpc action instance can be loaded at once */
164 163 if (ipgpc_action_exist) {
165 164 nvlist_free(nvlp);
166 165 return (EBUSY);
167 166 } else {
168 167 mutex_enter(&ipgpc_config_lock);
169 168 if (ipgpc_action_exist) {
170 169 nvlist_free(nvlp);
171 170 mutex_exit(&ipgpc_config_lock);
172 171 return (EBUSY);
173 172 }
174 173 /* check for action param IPP_ACTION_STATS_ENABLE */
175 174 if ((rc = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
176 175 &stat)) != 0) {
177 176 ipgpc_gather_stats = B_FALSE; /* disabled by default */
178 177 } else {
179 178 ipgpc_gather_stats = (boolean_t)stat;
180 179 }
181 180 if ((rc = ipgpc_initialize(aid)) != 0) {
182 181 ipgpc0dbg(("ipgpc_create_action: ipgpc_intialize " \
183 182 "error %d", rc));
184 183 ipgpc_destroy(IPP_DESTROY_REF);
185 184 ipgpc_action_exist = B_FALSE;
186 185 nvlist_free(nvlp);
187 186 mutex_exit(&ipgpc_config_lock);
188 187 return (rc);
189 188 }
190 189 ipgpc_action_exist = B_TRUE;
191 190 nvlist_free(nvlp);
192 191 mutex_exit(&ipgpc_config_lock);
193 192 return (0);
194 193 }
195 194 }
196 195
197 196 /*
198 197 * ipgpc_modify_action
199 198 *
200 199 * modify an instance of ipgpc
201 200 *
202 201 * nvlpp will contain the configuration type to switch off of. Use this
203 202 * to determine what modification should be made. If the modification fails,
204 203 * return the appropriate error.
205 204 */
206 205 /* ARGSUSED */
207 206 static int
208 207 ipgpc_modify_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
209 208 {
210 209 nvlist_t *nvlp;
211 210 int rc = 0;
212 211 uint8_t config_type;
213 212 uint32_t stat;
214 213 char *name;
215 214 int32_t filter_instance;
216 215 ipgpc_filter_t *filter;
217 216 ipgpc_class_t *aclass;
218 217
219 218 nvlp = *nvlpp;
220 219 *nvlpp = NULL; /* nvlist should be NULL when this returns */
221 220
222 221 if ((rc = nvlist_lookup_byte(nvlp, IPP_CONFIG_TYPE, &config_type))
223 222 != 0) {
224 223 nvlist_free(nvlp);
225 224 ipgpc0dbg(("ipgpc_modify_action: invalid configuration type"));
226 225 return (EINVAL);
227 226 }
228 227
229 228 switch (config_type) {
230 229 case IPP_SET: /* set an action parameter */
231 230 if ((rc = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
232 231 &stat)) != 0) {
233 232 nvlist_free(nvlp);
234 233 ipgpc0dbg(("ipgpc_modify_action: invalid IPP_SET " \
235 234 "parameter"));
236 235 return (EINVAL);
237 236 } else {
238 237 ipgpc_gather_stats = (boolean_t)stat;
239 238 }
240 239 break;
241 240 case CLASSIFIER_ADD_FILTER: /* add a filter */
242 241 filter = kmem_zalloc(sizeof (ipgpc_filter_t), KM_SLEEP);
243 242 if ((rc = ipgpc_parse_filter(filter, nvlp)) != 0) {
244 243 ipgpc0dbg(("ipgpc_modify_action: invalid filter"));
245 244 ipgpc_filter_destructor(filter);
246 245 kmem_free(filter, sizeof (ipgpc_filter_t));
247 246 break;
248 247 }
249 248 /* parse class name */
250 249 if ((rc = nvlist_lookup_string(nvlp, CLASSIFIER_CLASS_NAME,
251 250 &name)) != 0) {
252 251 ipgpc0dbg(("ipgpc_modify_action: class name missing"));
253 252 ipgpc_filter_destructor(filter);
254 253 kmem_free(filter, sizeof (ipgpc_filter_t));
255 254 break;
256 255 }
257 256 rc = ipgpc_addfilter(filter, name, flags);
258 257 if (rc != 0) {
259 258 ipgpc_filter_destructor(filter);
260 259 }
261 260 kmem_free(filter, sizeof (ipgpc_filter_t));
262 261 break;
263 262 case CLASSIFIER_ADD_CLASS: /* add a class */
264 263 aclass = kmem_zalloc(sizeof (ipgpc_class_t), KM_SLEEP);
265 264 if ((rc = ipgpc_parse_class(aclass, nvlp)) != 0) {
266 265 ipgpc0dbg(("ipgpc_modify_action: invalid class"));
267 266 kmem_free(aclass, sizeof (ipgpc_class_t));
268 267 break;
269 268 }
270 269 rc = ipgpc_addclass(aclass, flags);
271 270 kmem_free(aclass, sizeof (ipgpc_class_t));
272 271 break;
273 272 case CLASSIFIER_REMOVE_FILTER: /* remove a filter */
274 273 /* parse filter name */
275 274 if ((rc = nvlist_lookup_string(nvlp, CLASSIFIER_FILTER_NAME,
276 275 &name)) != 0) {
277 276 ipgpc0dbg(("ipgpc_modify_action: filtername missing"));
278 277 break;
279 278 }
280 279 /* parse optional filter_instance */
281 280 if (nvlist_lookup_int32(nvlp, IPGPC_FILTER_INSTANCE,
282 281 &filter_instance) != 0) {
283 282 filter_instance = -1;
284 283 }
285 284 rc = ipgpc_removefilter(name, filter_instance, flags);
286 285 break;
287 286 case CLASSIFIER_REMOVE_CLASS: /* remove a class */
288 287 /* parse class name */
289 288 if ((rc = nvlist_lookup_string(nvlp, CLASSIFIER_CLASS_NAME,
290 289 &name)) != 0) {
291 290 ipgpc0dbg(("ipgpc_modify_action: class name missing"));
292 291 break;
293 292 }
294 293 rc = ipgpc_removeclass(name, flags);
295 294 break;
296 295 case CLASSIFIER_MODIFY_FILTER: /* modify a filter */
297 296 rc = ipgpc_modifyfilter(&nvlp, flags);
298 297 break;
299 298 case CLASSIFIER_MODIFY_CLASS: /* modify a class */
300 299 rc = ipgpc_modifyclass(&nvlp, flags);
301 300 break;
302 301 default: /* invalid config type */
303 302 nvlist_free(nvlp);
304 303 ipgpc0dbg(("ipgpc_modify_action:invalid configuration type %u",
305 304 config_type));
306 305 return (EINVAL);
307 306 }
308 307 nvlist_free(nvlp); /* free the list */
309 308 return (rc); /* nvlist is passed back NULL */
310 309 }
311 310
312 311 /*
313 312 * ipgpc_destroy_action(aid, flags)
314 313 *
315 314 * action destructor for ipgpc
316 315 *
317 316 * Destroys an instance of the ipgpc action, if one exists. The
318 317 * ipgpc_action_lock is taken to block out any other destroys or creates
319 318 * that might be issued while the action is being destroyed
320 319 */
321 320 /* ARGSUSED */
322 321 static int
323 322 ipgpc_destroy_action(ipp_action_id_t aid, ipp_flags_t flags)
324 323 {
325 324 /* only destroy action if it exists */
326 325 if (ipgpc_action_exist == B_TRUE) {
327 326 mutex_enter(&ipgpc_config_lock);
328 327 if (ipgpc_action_exist == B_FALSE) {
329 328 mutex_exit(&ipgpc_config_lock);
330 329 return (EBUSY);
331 330 }
332 331 ipgpc_action_exist = B_FALSE;
333 332 ipgpc_destroy(flags);
334 333 mutex_exit(&ipgpc_config_lock);
335 334 }
336 335 return (0);
337 336 }
338 337
339 338 /*
340 339 * ipgpc_info(aid, fn, arg)
341 340 *
342 341 * configuration quering function for ipgpc
343 342 *
344 343 * passes back the configuration of ipgpc through allocated nvlists
345 344 * all action paramaters, classes and filters are built into nvlists
346 345 * and passed to the function pointer fn with arg
347 346 */
348 347 /* ARGSUSED */
349 348 static int
350 349 ipgpc_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
351 350 ipp_flags_t flags)
352 351 {
353 352 int rc;
354 353
355 354 /* set parameters */
356 355 if ((rc = ipgpc_params_info(fn, arg)) != 0) {
357 356 return (rc);
358 357 }
359 358
360 359 /* set all classes */
361 360 if ((rc = ipgpc_classes_info(fn, arg)) != 0) {
362 361 return (rc);
363 362 }
364 363
365 364 /* set all filters */
366 365 if ((rc = ipgpc_filters_info(fn, arg)) != 0) {
367 366 return (rc);
368 367 }
369 368 return (0);
370 369 }
371 370
372 371 /*
373 372 * ipgpc_invoke_action(aid, packet)
374 373 *
375 374 * packet processing function for ipgpc
376 375 *
377 376 * given packet the selector information is parsed and the classify
378 377 * function is called with those selectors. The classify function will
379 378 * return either a class or NULL, which represents a memory error and
380 379 * ENOMEM is returned. If the class returned is not NULL, the class and next
381 380 * action, associated with that class, are added to packet
382 381 */
383 382 /* ARGSUSED */
384 383 static int
385 384 ipgpc_invoke_action(ipp_action_id_t aid, ipp_packet_t *packet)
386 385 {
387 386 ipgpc_class_t *out_class;
388 387 hrtime_t start, end;
389 388 mblk_t *mp = NULL;
390 389 ip_priv_t *priv = NULL;
391 390 ill_t *ill = NULL;
392 391 ipha_t *ipha;
393 392 ip_proc_t callout_pos;
394 393 int af;
395 394 int rc;
396 395 ipgpc_packet_t pkt;
397 396 uint_t ill_idx;
398 397
399 398 /* extract packet data */
400 399 mp = ipp_packet_get_data(packet);
401 400 ASSERT(mp != NULL);
402 401
403 402 priv = (ip_priv_t *)ipp_packet_get_private(packet);
404 403 ASSERT(priv != NULL);
405 404
406 405 callout_pos = priv->proc;
407 406 ill_idx = priv->ill_index;
408 407
409 408 /* If we don't get an M_DATA, then return an error */
410 409 if (mp->b_datap->db_type != M_DATA) {
411 410 if ((mp->b_cont != NULL) &&
412 411 (mp->b_cont->b_datap->db_type == M_DATA)) {
413 412 mp = mp->b_cont; /* jump over the M_CTL into M_DATA */
414 413 } else {
415 414 ipgpc0dbg(("ipgpc_invoke_action: no data\n"));
416 415 atomic_inc_64(&ipgpc_epackets);
417 416 return (EINVAL);
418 417 }
419 418 }
420 419
421 420 /*
422 421 * Translate the callout_pos into the direction the packet is traveling
423 422 */
424 423 if (callout_pos != IPP_LOCAL_IN) {
425 424 if (callout_pos & IPP_LOCAL_OUT) {
426 425 callout_pos = IPP_LOCAL_OUT;
427 426 } else if (callout_pos & IPP_FWD_IN) {
428 427 callout_pos = IPP_FWD_IN;
429 428 } else { /* IPP_FWD_OUT */
430 429 callout_pos = IPP_FWD_OUT;
431 430 }
432 431 }
433 432
434 433 /* parse the packet from the message block */
435 434 ipha = (ipha_t *)mp->b_rptr;
436 435 /* Determine IP Header Version */
437 436 if (IPH_HDR_VERSION(ipha) == IPV4_VERSION) {
438 437 parse_packet(&pkt, mp);
439 438 af = AF_INET;
440 439 } else {
441 440 parse_packet6(&pkt, mp);
442 441 af = AF_INET6;
443 442 }
444 443
445 444 pkt.direction = callout_pos; /* set packet direction */
446 445
447 446 /* The ill_index could be 0 when called from forwarding (read) path */
448 447 if (ill_idx > 0)
449 448 ill = ill_lookup_on_ifindex_global_instance(ill_idx, B_FALSE);
450 449
451 450 if (ill != NULL) {
452 451 /*
453 452 * Since all IPP actions in an IPMP group are performed
454 453 * relative to the IPMP group interface, if this is an
455 454 * underlying interface in an IPMP group, use the IPMP
456 455 * group interface's index.
457 456 */
458 457 if (IS_UNDER_IPMP(ill))
459 458 pkt.if_index = ipmp_ill_get_ipmp_ifindex(ill);
460 459 else
461 460 pkt.if_index = ill->ill_phyint->phyint_ifindex;
462 461 /* Got the field from the ILL, go ahead and refrele */
463 462 ill_refrele(ill);
464 463 } else {
465 464 /* unknown if_index */
466 465 pkt.if_index = IPGPC_UNSPECIFIED;
467 466 }
468 467
469 468 if (ipgpc_debug > 5) {
470 469 /* print pkt under high debug level */
471 470 #ifdef IPGPC_DEBUG
472 471 print_packet(af, &pkt);
473 472 #endif
474 473 }
475 474 if (ipgpc_debug > 3) {
476 475 start = gethrtime(); /* start timer */
477 476 }
478 477
479 478 /* classify this packet */
480 479 out_class = ipgpc_classify(af, &pkt);
481 480
482 481 if (ipgpc_debug > 3) {
483 482 end = gethrtime(); /* stop timer */
484 483 }
485 484
486 485 /* ipgpc_classify will only return NULL if a memory error occured */
487 486 if (out_class == NULL) {
488 487 atomic_inc_64(&ipgpc_epackets);
489 488 return (ENOMEM);
490 489 }
491 490
492 491 ipgpc1dbg(("ipgpc_invoke_action: class = %s", out_class->class_name));
493 492 /* print time to classify(..) */
494 493 ipgpc2dbg(("ipgpc_invoke_action: time = %lld nsec\n", (end - start)));
495 494
496 495 if ((rc = ipp_packet_add_class(packet, out_class->class_name,
497 496 out_class->next_action)) != 0) {
498 497 atomic_inc_64(&ipgpc_epackets);
499 498 ipgpc0dbg(("ipgpc_invoke_action: ipp_packet_add_class " \
500 499 "failed with error %d", rc));
501 500 return (rc);
502 501 }
503 502 return (ipp_packet_next(packet, IPP_ACTION_CONT));
504 503 }
↓ open down ↓ |
420 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX