2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

util: Library routines for printing and scanning large hex integers.

Geneve options are variable length and up to 124 bytes long, which means
that they can't be easily manipulated by the integer string functions
like we do for other fields. This adds a few helper routines to make
these operations easier.

Signed-off-by: Jesse Gross <jesse@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
This commit is contained in:
Jesse Gross
2015-05-20 18:47:21 -07:00
parent 65da723b40
commit e7ae59f990
6 changed files with 113 additions and 31 deletions

View File

@@ -190,29 +190,14 @@ static char * OVS_WARN_UNUSED_RESULT
learn_parse_load_immediate(const char *s, struct ofpact_learn_spec *spec)
{
const char *full_s = s;
const char *arrow = strstr(s, "->");
struct mf_subfield dst;
union mf_subvalue imm;
char *error;
int err;
memset(&imm, 0, sizeof imm);
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X') && arrow) {
const char *in = arrow - 1;
uint8_t *out = imm.u8 + sizeof imm.u8 - 1;
int n = arrow - (s + 2);
int i;
for (i = 0; i < n; i++) {
int hexit = hexit_value(in[-i]);
if (hexit < 0) {
return xasprintf("%s: bad hex digit in value", full_s);
}
out[-(i / 2)] |= i % 2 ? hexit << 4 : hexit;
}
s = arrow;
} else {
ovs_be64 *last_be64 = &imm.be64[ARRAY_SIZE(imm.be64) - 1];
*last_be64 = htonll(strtoull(s, (char **) &s, 0));
err = parse_int_string(s, imm.u8, sizeof imm.u8, (char **) &s);
if (err) {
return xasprintf("%s: bad hex digit in value", full_s);
}
if (strncmp(s, "->", 2)) {