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