cangw: introduce uid command line option
Similar to referencing iptables rules by their line number this UID allows to reference created routing jobs, e.g. to alter configured data modifications. The UID is an optional non-zero value which can be provided at routing job creation time. When the UID is set the UID replaces the data modification configuration as job identification attribute e.g. at job removal time. The UID option is provided by mainline Linux 4.2+ Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>pull/1/merge
parent
dc374b074b
commit
8af831f377
16
cangw.c
16
cangw.c
|
|
@ -196,6 +196,7 @@ void print_usage(char *prg)
|
||||||
fprintf(stderr, "Options: -t (preserve src_dev rx timestamp)\n");
|
fprintf(stderr, "Options: -t (preserve src_dev rx timestamp)\n");
|
||||||
fprintf(stderr, " -e (echo sent frames - recommended on vcanx)\n");
|
fprintf(stderr, " -e (echo sent frames - recommended on vcanx)\n");
|
||||||
fprintf(stderr, " -i (allow to route to incoming interface)\n");
|
fprintf(stderr, " -i (allow to route to incoming interface)\n");
|
||||||
|
fprintf(stderr, " -u <uid> (user defined modification identifier)\n");
|
||||||
fprintf(stderr, " -l <hops> (limit the number of frame hops / routings)\n");
|
fprintf(stderr, " -l <hops> (limit the number of frame hops / routings)\n");
|
||||||
fprintf(stderr, " -f <filter> (set CAN filter)\n");
|
fprintf(stderr, " -f <filter> (set CAN filter)\n");
|
||||||
fprintf(stderr, " -m <mod> (set frame modifications)\n");
|
fprintf(stderr, " -m <mod> (set frame modifications)\n");
|
||||||
|
|
@ -418,6 +419,7 @@ int parse_rtlist(char *prgname, unsigned char *rxbuf, int len)
|
||||||
case CGW_MOD_OR:
|
case CGW_MOD_OR:
|
||||||
case CGW_MOD_XOR:
|
case CGW_MOD_XOR:
|
||||||
case CGW_MOD_SET:
|
case CGW_MOD_SET:
|
||||||
|
case CGW_MOD_UID:
|
||||||
case CGW_LIM_HOPS:
|
case CGW_LIM_HOPS:
|
||||||
case CGW_CS_XOR:
|
case CGW_CS_XOR:
|
||||||
case CGW_CS_CRC8:
|
case CGW_CS_CRC8:
|
||||||
|
|
@ -491,6 +493,10 @@ int parse_rtlist(char *prgname, unsigned char *rxbuf, int len)
|
||||||
printmod("SET", RTA_DATA(rta));
|
printmod("SET", RTA_DATA(rta));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CGW_MOD_UID:
|
||||||
|
printf("-u %X ", *(__u32 *)RTA_DATA(rta));
|
||||||
|
break;
|
||||||
|
|
||||||
case CGW_LIM_HOPS:
|
case CGW_LIM_HOPS:
|
||||||
printf("-l %d ", *(__u8 *)RTA_DATA(rta));
|
printf("-l %d ", *(__u8 *)RTA_DATA(rta));
|
||||||
break;
|
break;
|
||||||
|
|
@ -551,6 +557,7 @@ int main(int argc, char **argv)
|
||||||
struct nlmsgerr *rte;
|
struct nlmsgerr *rte;
|
||||||
unsigned int src_ifindex = 0;
|
unsigned int src_ifindex = 0;
|
||||||
unsigned int dst_ifindex = 0;
|
unsigned int dst_ifindex = 0;
|
||||||
|
__u32 uid = 0;
|
||||||
__u8 limit_hops = 0;
|
__u8 limit_hops = 0;
|
||||||
__u16 flags = 0;
|
__u16 flags = 0;
|
||||||
int len;
|
int len;
|
||||||
|
|
@ -570,7 +577,7 @@ int main(int argc, char **argv)
|
||||||
memset(&cs_xor, 0, sizeof(cs_xor));
|
memset(&cs_xor, 0, sizeof(cs_xor));
|
||||||
memset(&cs_crc8, 0, sizeof(cs_crc8));
|
memset(&cs_crc8, 0, sizeof(cs_crc8));
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ADFLs:d:teil:f:c:p:x:m:?")) != -1) {
|
while ((opt = getopt(argc, argv, "ADFLs:d:teiu:l:f:c:p:x:m:?")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
|
||||||
case 'A':
|
case 'A':
|
||||||
|
|
@ -613,6 +620,10 @@ int main(int argc, char **argv)
|
||||||
flags |= CGW_FLAGS_CAN_IIF_TX_OK;
|
flags |= CGW_FLAGS_CAN_IIF_TX_OK;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'u':
|
||||||
|
uid = strtoul(optarg, (char **)NULL, 16);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
if (sscanf(optarg, "%hhd", &limit_hops) != 1 || !(limit_hops)) {
|
if (sscanf(optarg, "%hhd", &limit_hops) != 1 || !(limit_hops)) {
|
||||||
printf("Bad hop limit definition '%s'.\n", optarg);
|
printf("Bad hop limit definition '%s'.\n", optarg);
|
||||||
|
|
@ -757,6 +768,9 @@ int main(int argc, char **argv)
|
||||||
if (have_cs_xor)
|
if (have_cs_xor)
|
||||||
addattr_l(&req.nh, sizeof(req), CGW_CS_XOR, &cs_xor, sizeof(cs_xor));
|
addattr_l(&req.nh, sizeof(req), CGW_CS_XOR, &cs_xor, sizeof(cs_xor));
|
||||||
|
|
||||||
|
if (uid)
|
||||||
|
addattr_l(&req.nh, sizeof(req), CGW_MOD_UID, &uid, sizeof(__u32));
|
||||||
|
|
||||||
if (limit_hops)
|
if (limit_hops)
|
||||||
addattr_l(&req.nh, sizeof(req), CGW_LIM_HOPS, &limit_hops, sizeof(__u8));
|
addattr_l(&req.nh, sizeof(req), CGW_LIM_HOPS, &limit_hops, sizeof(__u8));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ enum {
|
||||||
CGW_FILTER, /* specify struct can_filter on source CAN device */
|
CGW_FILTER, /* specify struct can_filter on source CAN device */
|
||||||
CGW_DELETED, /* number of deleted CAN frames (see max_hops param) */
|
CGW_DELETED, /* number of deleted CAN frames (see max_hops param) */
|
||||||
CGW_LIM_HOPS, /* limit the number of hops of this specific rule */
|
CGW_LIM_HOPS, /* limit the number of hops of this specific rule */
|
||||||
|
CGW_MOD_UID, /* user defined identifier for modification updates */
|
||||||
__CGW_MAX
|
__CGW_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -162,6 +163,10 @@ enum {
|
||||||
* load time of the can-gw module). This value is used to reduce the number of
|
* load time of the can-gw module). This value is used to reduce the number of
|
||||||
* possible hops for this gateway rule to a value smaller then max_hops.
|
* possible hops for this gateway rule to a value smaller then max_hops.
|
||||||
*
|
*
|
||||||
|
* CGW_MOD_UID (length 4 bytes):
|
||||||
|
* Optional non-zero user defined routing job identifier to alter existing
|
||||||
|
* modification settings at runtime.
|
||||||
|
*
|
||||||
* CGW_CS_XOR (length 4 bytes):
|
* CGW_CS_XOR (length 4 bytes):
|
||||||
* Set a simple XOR checksum starting with an initial value into
|
* Set a simple XOR checksum starting with an initial value into
|
||||||
* data[result-idx] using data[start-idx] .. data[end-idx]
|
* data[result-idx] using data[start-idx] .. data[end-idx]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue