xref: /titanic_41/usr/src/uts/common/ipp/dlcosmk/dlcosmk.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/stream.h>
31 #include <sys/dlpi.h>
32 #include <sys/strsun.h>
33 #include <netinet/in.h>
34 #include <netinet/ip6.h>
35 #include <inet/common.h>
36 #include <inet/ip.h>
37 #include <inet/ip6.h>
38 #include <inet/ip_if.h>
39 #include <ipp/dlcosmk/dlcosmk_impl.h>
40 
41 /* Module to mark the 802.1d user priority field for a given packet */
42 
43 /* Debug level */
44 int dlcosmk_debug = 0;
45 
46 /*
47  * Given a packet, this module marks the mblk with the appropriate b_band or
48  * dl_max value so that the VLAN driver marks the outgoing frame with the
49  * configured 802.1D user_priority value. For non-VLAN devices or for inbound
50  * packets, this module does not do anything (i.e. the packet is processed by
51  * the next action in the list, if present).
52  * This module does not free any mblks or packets in case or errors.
53  */
54 
55 int
56 dlcosmk_process(mblk_t **mpp, dlcosmk_data_t *dlcosmk_data, uint32_t ill_index,
57     ip_proc_t proc)
58 {
59 	ill_t *ill = NULL;
60 	mblk_t *mp;
61 
62 	ASSERT((mpp != NULL) && (*mpp != NULL));
63 	mp = *mpp;
64 
65 	/*
66 	 * The action module will receive an M_DATA or an M_CTL followed
67 	 * by an M_DATA. In the latter case skip the M_CTL.
68 	 */
69 	if (mp->b_datap->db_type != M_DATA) {
70 		if ((mp->b_cont == NULL) ||
71 		    (mp->b_cont->b_datap->db_type != M_DATA)) {
72 			atomic_add_64(&dlcosmk_data->epackets, 1);
73 			dlcosmk0dbg(("dlcosmk_process: no data\n"));
74 			return (EINVAL);
75 		}
76 	}
77 
78 	/* Update global stats */
79 	atomic_add_64(&dlcosmk_data->npackets, 1);
80 
81 	/*
82 	 * This should only be called for outgoing packets. For inbound, just
83 	 * send it along.
84 	 */
85 	if ((proc == IPP_LOCAL_IN) || (proc == IPP_FWD_IN)) {
86 		dlcosmk2dbg(("dlcosmk_process:cannot mark incoming packets\n"));
87 		atomic_add_64(&dlcosmk_data->ipackets, 1);
88 		return (0);
89 	}
90 
91 	if ((ill_index == 0) ||
92 	    ((ill = ill_lookup_on_ifindex(ill_index, B_FALSE, NULL, NULL,
93 		NULL, NULL)) == NULL)) {
94 		dlcosmk2dbg(("dlcosmk_process:invalid ill index %u\n",
95 		    ill_index));
96 		atomic_add_64(&dlcosmk_data->ipackets, 1);
97 		return (0);
98 	}
99 
100 	/*
101 	 * Check if the interface supports CoS marking. If not send it to the
102 	 * next action in the chain
103 	 */
104 	if (!(ill->ill_flags & ILLF_COS_ENABLED)) {
105 		dlcosmk2dbg(("dlcosmk_process:ill %u does not support CoS\n",
106 		    ill_index));
107 		atomic_add_64(&dlcosmk_data->ipackets, 1);
108 		ill_refrele(ill);
109 		return (0);
110 	}
111 	ill_refrele(ill);
112 
113 
114 	/*
115 	 * Mark the b_band for fastpath messages or dl_priority.dl_max for
116 	 * DL_UNITDATA_REQ messages. For, others just pass it along.
117 	 */
118 	switch (DB_TYPE(mp)) {
119 		case M_PROTO:
120 		case M_PCPROTO:
121 			{ 	/* DL_UNITDATA */
122 				dl_unitdata_req_t *dlur;
123 				dlur = (dl_unitdata_req_t *)mp->b_rptr;
124 
125 				/* DL_UNITDATA message?? */
126 				if (dlur->dl_primitive == DL_UNITDATA_REQ) {
127 					dlur->dl_priority.dl_max =
128 					    dlcosmk_data->dl_max;
129 				} else {
130 					atomic_add_64(&dlcosmk_data->ipackets,
131 					    1);
132 				}
133 				break;
134 			}
135 		case M_DATA:
136 			/* fastpath message */
137 			mp->b_band = dlcosmk_data->b_band;
138 			break;
139 		default:
140 			atomic_add_64(&dlcosmk_data->ipackets, 1);
141 			break;
142 	}
143 
144 	return (0);
145 }
146