- struct dlil_proto_reg_str dlilSpec;
- struct ndrv_protocol_desc ndrvSpec;
- struct dlil_demux_desc* dlilDemux = NULL;
- struct ndrv_demux_desc* ndrvDemux = NULL;
- int error = 0;
-
- /* Sanity checking */
- if (np->nd_proto_family != PF_NDRV)
- return EBUSY;
- if (np->nd_if == NULL)
- return EINVAL;
- if (sopt->sopt_valsize != sizeof(struct ndrv_protocol_desc))
- return EINVAL;
-
- /* Copy the ndrvSpec */
- error = sooptcopyin(sopt, &ndrvSpec, sizeof(struct ndrv_protocol_desc),
- sizeof(struct ndrv_protocol_desc));
- if (error != 0)
- return error;
-
- /* Verify the parameter */
- if (ndrvSpec.version > NDRV_PROTOCOL_DESC_VERS)
- return ENOTSUP; // version is too new!
- else if (ndrvSpec.version < 1)
- return EINVAL; // version is not valid
-
- /* Allocate storage for demux array */
- MALLOC(ndrvDemux, struct ndrv_demux_desc*,
- ndrvSpec.demux_count * sizeof(struct ndrv_demux_desc), M_TEMP, M_WAITOK);
- if (ndrvDemux == NULL)
- return ENOMEM;
-
- /* Allocate enough dlil_demux_descs */
- MALLOC(dlilDemux, struct dlil_demux_desc*,
- sizeof(*dlilDemux) * ndrvSpec.demux_count, M_TEMP, M_WAITOK);
- if (dlilDemux == NULL)
- error = ENOMEM;
-
- if (error == 0)
- {
- /* Copy the ndrv demux array from userland */
- error = copyin(CAST_USER_ADDR_T(ndrvSpec.demux_list), ndrvDemux,
- ndrvSpec.demux_count * sizeof(struct ndrv_demux_desc));
- ndrvSpec.demux_list = ndrvDemux;
- }
-
- if (error == 0)
- {
- /* At this point, we've at least got enough bytes to start looking around */
- u_long demuxOn = 0;
-
- bzero(&dlilSpec, sizeof(dlilSpec));
- TAILQ_INIT(&dlilSpec.demux_desc_head);
- dlilSpec.interface_family = np->nd_family;
- dlilSpec.unit_number = np->nd_unit;
- dlilSpec.input = ndrv_input;
- dlilSpec.event = ndrv_event;
- dlilSpec.protocol_family = ndrvSpec.protocol_family;
-
- for (demuxOn = 0; demuxOn < ndrvSpec.demux_count; demuxOn++)
- {
- /* Convert an ndrv_demux_desc to a dlil_demux_desc */
- error = ndrv_to_dlil_demux(&ndrvSpec.demux_list[demuxOn], &dlilDemux[demuxOn]);
- if (error)
- break;
-
- /* Add the dlil_demux_desc to the list */
- TAILQ_INSERT_TAIL(&dlilSpec.demux_desc_head, &dlilDemux[demuxOn], next);
- }
- }
-
- if (error == 0)
- {
- /* We've got all our ducks lined up...lets attach! */
- error = dlil_attach_protocol(&dlilSpec);
- if (error == 0)
- np->nd_proto_family = dlilSpec.protocol_family;
- }
-
- /* Free any memory we've allocated */
- if (dlilDemux)
- FREE(dlilDemux, M_TEMP);
- if (ndrvDemux)
- FREE(ndrvDemux, M_TEMP);
-
- return error;
+ struct ifnet_attach_proto_param proto_param;
+ struct ndrv_protocol_desc ndrvSpec;
+ struct ndrv_demux_desc* ndrvDemux = NULL;
+ int error = 0;
+ struct socket * so = np->nd_socket;
+ user_addr_t user_addr;
+
+ /* Sanity checking */
+ if (np->nd_proto_family != PF_NDRV)
+ return EBUSY;
+ if (np->nd_if == NULL)
+ return EINVAL;
+
+ /* Copy the ndrvSpec */
+ if (proc_is64bit(sopt->sopt_p)) {
+ struct ndrv_protocol_desc64 ndrvSpec64;
+
+ if (sopt->sopt_valsize != sizeof(ndrvSpec64))
+ return EINVAL;
+
+ error = sooptcopyin(sopt, &ndrvSpec64, sizeof(ndrvSpec64), sizeof(ndrvSpec64));
+ if (error != 0)
+ return error;
+
+ ndrvSpec.version = ndrvSpec64.version;
+ ndrvSpec.protocol_family = ndrvSpec64.protocol_family;
+ ndrvSpec.demux_count = ndrvSpec64.demux_count;
+
+ user_addr = ndrvSpec64.demux_list;
+ }
+ else {
+ struct ndrv_protocol_desc32 ndrvSpec32;
+
+ if (sopt->sopt_valsize != sizeof(ndrvSpec32))
+ return EINVAL;
+
+ error = sooptcopyin(sopt, &ndrvSpec32, sizeof(ndrvSpec32), sizeof(ndrvSpec32));
+ if (error != 0)
+ return error;
+
+ ndrvSpec.version = ndrvSpec32.version;
+ ndrvSpec.protocol_family = ndrvSpec32.protocol_family;
+ ndrvSpec.demux_count = ndrvSpec32.demux_count;
+
+ user_addr = CAST_USER_ADDR_T(ndrvSpec32.demux_list);
+ }
+
+ /* Verify the parameter */
+ if (ndrvSpec.version > NDRV_PROTOCOL_DESC_VERS)
+ return ENOTSUP; // version is too new!
+ else if (ndrvSpec.version < 1)
+ return EINVAL; // version is not valid
+ else if (ndrvSpec.demux_count > NDRV_PROTODEMUX_COUNT || ndrvSpec.demux_count == 0)
+ return EINVAL; // demux_count is not valid
+
+ bzero(&proto_param, sizeof(proto_param));
+ proto_param.demux_count = ndrvSpec.demux_count;
+
+ /* Allocate storage for demux array */
+ MALLOC(ndrvDemux, struct ndrv_demux_desc*, proto_param.demux_count *
+ sizeof(struct ndrv_demux_desc), M_TEMP, M_WAITOK);
+ if (ndrvDemux == NULL)
+ return ENOMEM;
+
+ /* Allocate enough ifnet_demux_descs */
+ MALLOC(proto_param.demux_array, struct ifnet_demux_desc*,
+ sizeof(*proto_param.demux_array) * ndrvSpec.demux_count,
+ M_TEMP, M_WAITOK);
+ if (proto_param.demux_array == NULL)
+ error = ENOMEM;
+
+ if (error == 0)
+ {
+ /* Copy the ndrv demux array from userland */
+ error = copyin(user_addr, ndrvDemux,
+ ndrvSpec.demux_count * sizeof(struct ndrv_demux_desc));
+ ndrvSpec.demux_list = ndrvDemux;
+ }
+
+ if (error == 0)
+ {
+ /* At this point, we've at least got enough bytes to start looking around */
+ u_int32_t demuxOn = 0;
+
+ proto_param.demux_count = ndrvSpec.demux_count;
+ proto_param.input = ndrv_input;
+ proto_param.event = ndrv_event;
+
+ for (demuxOn = 0; demuxOn < ndrvSpec.demux_count; demuxOn++)
+ {
+ /* Convert an ndrv_demux_desc to a ifnet_demux_desc */
+ error = ndrv_to_ifnet_demux(&ndrvSpec.demux_list[demuxOn],
+ &proto_param.demux_array[demuxOn]);
+ if (error)
+ break;
+ }
+ }
+
+ if (error == 0)
+ {
+ /* We've got all our ducks lined up...lets attach! */
+ socket_unlock(so, 0);
+ error = ifnet_attach_protocol(np->nd_if, ndrvSpec.protocol_family,
+ &proto_param);
+ socket_lock(so, 0);
+ if (error == 0)
+ np->nd_proto_family = ndrvSpec.protocol_family;
+ }
+
+ /* Free any memory we've allocated */
+ if (proto_param.demux_array)
+ FREE(proto_param.demux_array, M_TEMP);
+ if (ndrvDemux)
+ FREE(ndrvDemux, M_TEMP);
+
+ return error;