Filter incoming requests per card

If multiple cards are installed, firewire-core will emit requests from
nodes on any of the cards to clients.  This is not expected by
libraw1394 clients since a raw1394handle_t is bound to a single card
alias port.

On kernel 2.6.36 and newer we can filter out requests from other cards.
Note that we still need to call the response ioctl in order to release
kernel resources associated with an inbound transaction.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
This commit is contained in:
Stefan Richter 2010-06-20 21:50:09 +02:00
parent d3ace3dfb4
commit 926e9ea3ad
2 changed files with 17 additions and 3 deletions

View File

@ -220,14 +220,14 @@ handle_lost_device(fw_handle_t handle, int i)
struct address_closure { struct address_closure {
int (*callback)(raw1394handle_t handle, struct address_closure *ac, int (*callback)(raw1394handle_t handle, struct address_closure *ac,
int tcode, unsigned long long offset, int tcode, unsigned long long offset,
int source_node_id, unsigned kernel_handle, int source_node_id, int card, unsigned kernel_handle,
size_t length, void *data); size_t length, void *data);
}; };
static int static int
handle_fcp_request(raw1394handle_t handle, struct address_closure *ac, handle_fcp_request(raw1394handle_t handle, struct address_closure *ac,
int tcode, unsigned long long offset, int source_node_id, int tcode, unsigned long long offset, int source_node_id,
unsigned kernel_handle, size_t length, void *data) int card, unsigned kernel_handle, size_t length, void *data)
{ {
struct fw_cdev_send_response response; struct fw_cdev_send_response response;
int is_response; int is_response;
@ -247,6 +247,9 @@ handle_fcp_request(raw1394handle_t handle, struct address_closure *ac,
FW_CDEV_IOC_SEND_RESPONSE, &response) < 0) FW_CDEV_IOC_SEND_RESPONSE, &response) < 0)
return -1; return -1;
if (card != handle->mode.fw->card)
return 0;
if (response.rcode != RCODE_COMPLETE) if (response.rcode != RCODE_COMPLETE)
return 0; return 0;
@ -315,6 +318,7 @@ handle_device_event(raw1394handle_t handle,
u->request.offset, u->request.offset,
/* wild guess, but can't do better */ /* wild guess, but can't do better */
fwhandle->devices[i].node_id, fwhandle->devices[i].node_id,
fwhandle->card,
u->request.handle, u->request.handle,
u->request.length, u->request.data); u->request.length, u->request.data);
@ -324,6 +328,7 @@ handle_device_event(raw1394handle_t handle,
return ac->callback(handle, ac, u->request2.tcode, return ac->callback(handle, ac, u->request2.tcode,
u->request2.offset, u->request2.offset,
u->request2.source_node_id, u->request2.source_node_id,
u->request2.card,
u->request2.handle, u->request2.handle,
u->request2.length, u->request2.data); u->request2.length, u->request2.data);
#endif #endif
@ -673,6 +678,7 @@ int fw_set_port(fw_handle_t handle, int port)
if (reset.node_id == reset.local_node_id) if (reset.node_id == reset.local_node_id)
handle->local_device = &handle->devices[i]; handle->local_device = &handle->devices[i];
handle->card = get_info.card;
handle->generation = reset.generation; handle->generation = reset.generation;
handle->abi_version = get_info.version; handle->abi_version = get_info.version;
@ -730,7 +736,7 @@ struct allocation {
static int static int
handle_arm_request(raw1394handle_t handle, struct address_closure *ac, handle_arm_request(raw1394handle_t handle, struct address_closure *ac,
int tcode, unsigned long long offset, int source_node_id, int tcode, unsigned long long offset, int source_node_id,
unsigned kernel_handle, size_t length, void *data) int card, unsigned kernel_handle, size_t length, void *data)
{ {
fw_handle_t fwhandle = handle->mode.fw; fw_handle_t fwhandle = handle->mode.fw;
struct allocation *allocation = (struct allocation *) ac; struct allocation *allocation = (struct allocation *) ac;
@ -809,6 +815,13 @@ handle_arm_request(raw1394handle_t handle, struct address_closure *ac,
return -1; return -1;
} }
/*
* libraw1394 clients do not expect requests from nodes on
* a card other than the one set by raw1394_set_port().
*/
if (card != fwhandle->card)
return 0;
if (!(allocation->notification_options & type)) if (!(allocation->notification_options & type))
return 0; return 0;

View File

@ -79,6 +79,7 @@ struct fw_handle {
struct port ports[MAX_PORTS]; struct port ports[MAX_PORTS];
int port_count; int port_count;
int err; int err;
int card;
int generation; int generation;
int abi_version; int abi_version;
void *userdata; void *userdata;