4

SocketCAN's description says about adding some filters to a socket:

struct can_filter rfilter[2];

rfilter[0].can_id   = 0x123;
rfilter[0].can_mask = CAN_SFF_MASK;
rfilter[1].can_id   = 0x200;
rfilter[1].can_mask = 0x700;

setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));

But it doesn't say anything abou how to remove a specific filter if I have multiple ones on the same socket. Could someone please guess/explain this for me?

(Is this thing written down somewhere or I should gain a lot of general experience with linux sockets first before even touching SocketCAN?)

Greenberet
  • 490
  • 1
  • 5
  • 18
  • 1
    how about doing the following? step 1: setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter_1, sizeof(rfilter_1)); where rfilter_1 is any config of filters. Then let's say you want to remove some filters from this config + add new filters to it, then create a new rfilter_2 with that config, and do step 2: setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); followed by setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter_2, sizeof(rfilter_2)); – ARD Sep 04 '19 at 19:16
  • @ARD That is what I'm afraid will be the solution. Or something like that. If i'm correct, after having a look at function `raw_setsockopt()` at ./kernel/2.6/net/can/raw.c:471 this funcion always replaces all the old filter(s) with the given new one(s) so I wouldn't even need to care about clearing the existing filters. The sad thing about this is that I will have to keep track of all the current filters myself in order to be able to recreate the new filter config `rfilter`. – Greenberet Sep 04 '19 at 19:42

0 Answers0