diff options
author | Sven Eckelmann <sven@narfation.org> | 2012-10-17 15:10:39 -0400 |
---|---|---|
committer | Antonio Quartulli <ordex@autistici.org> | 2012-11-21 06:35:41 -0500 |
commit | 95a066d82c422c812c10bfd4de01225b1714fa45 (patch) | |
tree | e040f780728ea700af9d2df22e28b9188f586071 /net/batman-adv | |
parent | 60d8cce7c53f188d99cb01a0a013cf3544f35e29 (diff) |
batman-adv: Add function to calculate crc32c for the skb payload
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Diffstat (limited to 'net/batman-adv')
-rw-r--r-- | net/batman-adv/Kconfig | 1 | ||||
-rw-r--r-- | net/batman-adv/main.c | 34 | ||||
-rw-r--r-- | net/batman-adv/main.h | 1 |
3 files changed, 36 insertions, 0 deletions
diff --git a/net/batman-adv/Kconfig b/net/batman-adv/Kconfig index 250e0b58109c..8d8afb134b3a 100644 --- a/net/batman-adv/Kconfig +++ b/net/batman-adv/Kconfig | |||
@@ -6,6 +6,7 @@ config BATMAN_ADV | |||
6 | tristate "B.A.T.M.A.N. Advanced Meshing Protocol" | 6 | tristate "B.A.T.M.A.N. Advanced Meshing Protocol" |
7 | depends on NET | 7 | depends on NET |
8 | select CRC16 | 8 | select CRC16 |
9 | select LIBCRC32C | ||
9 | default n | 10 | default n |
10 | help | 11 | help |
11 | B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is | 12 | B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is |
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index dc33a0c484a4..f65a222b7b83 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c | |||
@@ -17,6 +17,8 @@ | |||
17 | * 02110-1301, USA | 17 | * 02110-1301, USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/crc32c.h> | ||
21 | #include <linux/highmem.h> | ||
20 | #include "main.h" | 22 | #include "main.h" |
21 | #include "sysfs.h" | 23 | #include "sysfs.h" |
22 | #include "debugfs.h" | 24 | #include "debugfs.h" |
@@ -420,6 +422,38 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset) | |||
420 | return 0; | 422 | return 0; |
421 | } | 423 | } |
422 | 424 | ||
425 | /** | ||
426 | * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in | ||
427 | * the header | ||
428 | * @skb: skb pointing to fragmented socket buffers | ||
429 | * @payload_ptr: Pointer to position inside the head buffer of the skb | ||
430 | * marking the start of the data to be CRC'ed | ||
431 | * | ||
432 | * payload_ptr must always point to an address in the skb head buffer and not to | ||
433 | * a fragment. | ||
434 | */ | ||
435 | __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr) | ||
436 | { | ||
437 | u32 crc = 0; | ||
438 | unsigned int from; | ||
439 | unsigned int to = skb->len; | ||
440 | struct skb_seq_state st; | ||
441 | const u8 *data; | ||
442 | unsigned int len; | ||
443 | unsigned int consumed = 0; | ||
444 | |||
445 | from = (unsigned int)(payload_ptr - skb->data); | ||
446 | |||
447 | skb_prepare_seq_read(skb, from, to, &st); | ||
448 | while ((len = skb_seq_read(consumed, &data, &st)) != 0) { | ||
449 | crc = crc32c(crc, data, len); | ||
450 | consumed += len; | ||
451 | } | ||
452 | skb_abort_seq_read(&st); | ||
453 | |||
454 | return htonl(crc); | ||
455 | } | ||
456 | |||
423 | static int batadv_param_set_ra(const char *val, const struct kernel_param *kp) | 457 | static int batadv_param_set_ra(const char *val, const struct kernel_param *kp) |
424 | { | 458 | { |
425 | struct batadv_algo_ops *bat_algo_ops; | 459 | struct batadv_algo_ops *bat_algo_ops; |
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index 8f149bb66817..ce5e5b96ebee 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h | |||
@@ -174,6 +174,7 @@ void batadv_recv_handler_unregister(uint8_t packet_type); | |||
174 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops); | 174 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops); |
175 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name); | 175 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name); |
176 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset); | 176 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset); |
177 | __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr); | ||
177 | 178 | ||
178 | /** | 179 | /** |
179 | * enum batadv_dbg_level - available log levels | 180 | * enum batadv_dbg_level - available log levels |