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.
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.
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]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/types.h>
28 #include <sys/stream.h>
30 #include <net/bpfdesc.h>
33 * This file provides the link to the functions required from the mac
34 * module. It is currently in bpf, rather than mac (like ipnet_bpf)
35 * because of the mac/dls split. The bpf driver needs to know when
36 * interfaces appear and disappear and the best place for that is in
37 * dls. Unfortunately all of the other functions used here are found
38 * in the mac module, making it seem ill suited to being at home in
39 * dls. Similarly it has even less purpose being in mac as it is
42 static int mac_bpf_open(const char *, uintptr_t *, zoneid_t
);
43 static void mac_bpf_close(uintptr_t);
44 static const char *mac_bpf_name(uintptr_t);
45 static int mac_bpf_type(uintptr_t);
46 static void mac_bpf_sdu_get(uintptr_t, uint_t
*);
47 static int mac_bpf_tx(uintptr_t, mblk_t
*);
48 static uintptr_t mac_bpf_promisc_add(uintptr_t, int, void *, uintptr_t *, int);
49 static void mac_bpf_promisc_remove(uintptr_t);
50 static int mac_bpf_client_open(uintptr_t, uintptr_t *);
51 static void mac_bpf_client_close(uintptr_t);
52 static const char *mac_bpf_client_name(uintptr_t);
53 static int mac_bpf_getdlt(uintptr_t, uint_t
*);
54 static int mac_bpf_getlinkid(const char *, datalink_id_t
*, zoneid_t
);
55 static int mac_bpf_getzone(uintptr_t, zoneid_t
*);
57 bpf_provider_t bpf_mac
= {
66 mac_bpf_promisc_remove
,
77 mac_bpf_open(const char *name
, uintptr_t *mhandlep
, zoneid_t zoneid
)
79 return (mac_open_by_linkname(name
, (mac_handle_t
*)mhandlep
));
83 mac_bpf_close(uintptr_t mhandle
)
85 mac_close((mac_handle_t
)mhandle
);
89 mac_bpf_name(uintptr_t mhandle
)
91 return (mac_name((mac_handle_t
)mhandle
));
95 mac_bpf_type(uintptr_t mhandle
)
97 return (mac_nativetype((mac_handle_t
)mhandle
));
101 mac_bpf_sdu_get(uintptr_t mhandle
, uint_t
*mtup
)
103 mac_sdu_get((mac_handle_t
)mhandle
, NULL
, mtup
);
107 mac_bpf_tx(uintptr_t chandle
, mblk_t
*pkt
)
110 * If the mac layer cannot deliver a packet as requested by BPF then
111 * simply have the mac layer drop it. BPF isn't interested in doing
112 * any amount of retry - that's left to the application.
114 return (mac_tx((mac_client_handle_t
)chandle
, pkt
, 0,
115 MAC_DROP_ON_NO_DESC
, NULL
));
119 mac_bpf_promisc_add(uintptr_t chandle
, int how
, void *arg
, uintptr_t *promisc
,
122 return (mac_promisc_add((mac_client_handle_t
)chandle
, how
, bpf_mtap
,
123 arg
, (mac_promisc_handle_t
*)promisc
, flags
));
127 mac_bpf_promisc_remove(uintptr_t phandle
)
129 mac_promisc_remove((mac_promisc_handle_t
)phandle
);
133 mac_bpf_client_open(uintptr_t mhandle
, uintptr_t *chandlep
)
135 return (mac_client_open((mac_handle_t
)mhandle
,
136 (mac_client_handle_t
*)chandlep
, NULL
,
137 MAC_OPEN_FLAGS_USE_DATALINK_NAME
));
141 mac_bpf_client_close(uintptr_t chandle
)
143 mac_client_close((mac_client_handle_t
)chandle
, 0);
147 mac_bpf_client_name(uintptr_t chandle
)
149 return (mac_client_name((mac_client_handle_t
)chandle
));
154 mac_bpf_getlinkid(const char *name
, datalink_id_t
*idp
, zoneid_t zoneid
)
159 * If at first we don't succeed, try again, just in case it is in
160 * hiding. The first call requires the datalink management daemon
161 * (the authorative source of information about name to id mapping)
162 * to be present and answering upcalls, the seond does not.
164 error
= dls_mgmt_get_linkid(name
, idp
);
166 error
= dls_devnet_macname2linkid(name
, idp
);
172 mac_bpf_getzone(uintptr_t handle
, zoneid_t
*zip
)
174 mac_perim_handle_t mph
;
177 mac_perim_enter_by_mh((mac_handle_t
)handle
, &mph
);
178 error
= dls_link_getzid(mac_name((mac_handle_t
)handle
), zip
);
184 mac_bpf_getdlt(uintptr_t handle
, uint_t
*dltp
)
186 *dltp
= mac_nativetype((mac_handle_t
)handle
);