ipcfg:Version the binary structure

This commit is contained in:
David Sidrane 2020-10-06 06:07:55 -07:00 committed by patacongo
parent a627561c8f
commit 833d231031
2 changed files with 21 additions and 14 deletions

View File

@ -37,9 +37,10 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define MAX_LINESIZE 80 #define IPCFG_VERSION 1 /* Increment this if the data/structure changes */
#define MAX_IPv4PROTO IPv4PROTO_FALLBACK #define MAX_LINESIZE 80
#define MAX_IPv6PROTO IPv6PROTO_FALLBACK #define MAX_IPv4PROTO IPv4PROTO_FALLBACK
#define MAX_IPv6PROTO IPv6PROTO_FALLBACK
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
@ -49,7 +50,8 @@
struct ipcfg_header_s struct ipcfg_header_s
{ {
uint8_t next; /* Offset to the next IP configuration record */ uint8_t next; /* Offset to the next IP configuration record */
uint8_t version; /* For binary compatibility */
sa_family_t type; /* Either AF_INET or AF_INET6 */ sa_family_t type; /* Either AF_INET or AF_INET6 */
}; };

View File

@ -223,11 +223,12 @@ static int ipcfg_find_binary(int fd, sa_family_t af)
return (int)ret; return (int)ret;
} }
else if (hdr.type == af) else if (hdr.version == IPCFG_VERSION && hdr.type == af)
{ {
return OK; return OK;
} }
else if (hdr.type != AF_INET && hdr.type != AF_INET6) else if (hdr.version != IPCFG_VERSION ||
hdr.type != AF_INET && hdr.type != AF_INET6)
{ {
return -EINVAL; return -EINVAL;
} }
@ -416,8 +417,9 @@ int ipcfg_write_binary_ipv4(FAR const char *path,
/* Write the IPv4 file header */ /* Write the IPv4 file header */
hdr.next = ipv6 ? sizeof(struct ipv4cfg_s) : 0; hdr.next = ipv6 ? sizeof(struct ipv4cfg_s) : 0;
hdr.type = AF_INET; hdr.type = AF_INET;
hdr.version = IPCFG_VERSION;
ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s)); ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s));
if (ret < 0) if (ret < 0)
@ -440,8 +442,9 @@ int ipcfg_write_binary_ipv4(FAR const char *path,
{ {
/* Write the IPv6 header */ /* Write the IPv6 header */
hdr.next = 0; hdr.next = 0;
hdr.type = AF_INET6; hdr.type = AF_INET6;
hdr.version = IPCFG_VERSION;
ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s)); ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s));
if (ret >= 0) if (ret >= 0)
@ -523,8 +526,9 @@ int ipcfg_write_binary_ipv6(FAR const char *path,
{ {
/* Write the IPv4 header */ /* Write the IPv4 header */
hdr.next = sizeof(struct ipv4cfg_s); hdr.next = sizeof(struct ipv4cfg_s);
hdr.type = AF_INET; hdr.type = AF_INET;
hdr.version = IPCFG_VERSION;
ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s)); ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s));
if (ret < 0) if (ret < 0)
@ -546,8 +550,9 @@ int ipcfg_write_binary_ipv6(FAR const char *path,
/* Write the IPv6 file header */ /* Write the IPv6 file header */
hdr.next = 0; hdr.next = 0;
hdr.type = AF_INET6; hdr.type = AF_INET6;
hdr.version = IPCFG_VERSION;
ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s)); ret = ipcfg_write_binary(fd, &hdr, sizeof(struct ipcfg_header_s));
if (ret >= 0) if (ret >= 0)