diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2017-05-17 17:36:31 +0200 |
|---|---|---|
| committer | Andrey Konovalov <andreyknvl@google.com> | 2017-06-12 19:48:23 +0200 |
| commit | 7b43c5f9f723c6d593cb03065ea3371b86c350c7 (patch) | |
| tree | c2c838979849eeeba41c6cc3df282aef8060311c /executor | |
| parent | 4ca73f9c87f1098a69deb761a8d23f040d8e89db (diff) | |
executor: move inet checksum code under ifdef
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/common.h | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/executor/common.h b/executor/common.h index af87856fb..46356c6a9 100644 --- a/executor/common.h +++ b/executor/common.h @@ -320,6 +320,38 @@ void debug_dump_data(const char* data, int length) } #endif // SYZ_TUN_ENABLE +#if defined(__NR_syz_emit_ethernet) || defined(__NR_syz_test) +struct csum_inet { + uint32_t acc; +}; + +void csum_inet_init(struct csum_inet* csum) +{ + csum->acc = 0; +} + +void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) +{ + if (length == 0) + return; + + size_t i; + for (i = 0; i < length - 1; i += 2) + csum->acc += *(uint16_t*)&data[i]; + + if (length & 1) + csum->acc += (uint16_t)data[length - 1]; + + while (csum->acc > 0xffff) + csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); +} + +uint16_t csum_inet_digest(struct csum_inet* csum) +{ + return ~csum->acc; +} +#endif + #ifdef __NR_syz_emit_ethernet static uintptr_t syz_emit_ethernet(uintptr_t a0, uintptr_t a1) { @@ -426,36 +458,6 @@ static uintptr_t syz_extract_tcp_res(uintptr_t a0, uintptr_t a1, uintptr_t a2) } #endif -struct csum_inet { - uint32_t acc; -}; - -void csum_inet_init(struct csum_inet* csum) -{ - csum->acc = 0; -} - -void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) -{ - if (length == 0) - return; - - size_t i; - for (i = 0; i < length - 1; i += 2) - csum->acc += *(uint16_t*)&data[i]; - - if (length & 1) - csum->acc += (uint16_t)data[length - 1]; - - while (csum->acc > 0xffff) - csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); -} - -uint16_t csum_inet_digest(struct csum_inet* csum) -{ - return ~csum->acc; -} - #ifdef __NR_syz_open_dev static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) { |
