Skip to content

Commit 30d77c9

Browse files
committed
net: Dump regular sit device
Nothing special here, just parse all known NLAs and keep them on the image. Issue #11 Signed-off-by: Pavel Emelyanov <[email protected]> Signed-off-by: Andrei Vagin <[email protected]>
1 parent e085fc1 commit 30d77c9

File tree

4 files changed

+153
-4
lines changed

4 files changed

+153
-4
lines changed

criu/net.c

+127-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@
5555
#define IFLA_MACVLAN_FLAGS 2
5656
#endif
5757

58+
enum {
59+
IFLA_IPTUN_UNSPEC,
60+
IFLA_IPTUN_LINK,
61+
IFLA_IPTUN_LOCAL,
62+
IFLA_IPTUN_REMOTE,
63+
IFLA_IPTUN_TTL,
64+
IFLA_IPTUN_TOS,
65+
IFLA_IPTUN_ENCAP_LIMIT,
66+
IFLA_IPTUN_FLOWINFO,
67+
IFLA_IPTUN_FLAGS,
68+
IFLA_IPTUN_PROTO,
69+
IFLA_IPTUN_PMTUDISC,
70+
IFLA_IPTUN_6RD_PREFIX,
71+
IFLA_IPTUN_6RD_RELAY_PREFIX,
72+
IFLA_IPTUN_6RD_PREFIXLEN,
73+
IFLA_IPTUN_6RD_RELAY_PREFIXLEN,
74+
IFLA_IPTUN_ENCAP_TYPE,
75+
IFLA_IPTUN_ENCAP_FLAGS,
76+
IFLA_IPTUN_ENCAP_SPORT,
77+
IFLA_IPTUN_ENCAP_DPORT,
78+
__IFLA_IPTUN_MAX,
79+
};
80+
#define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
81+
5882
static int ns_sysfs_fd = -1;
5983

6084
int read_ns_sys_file(char *path, char *buf, int len)
@@ -658,8 +682,108 @@ static int dump_one_gre(struct ifinfomsg *ifi, char *kind,
658682
return dump_unknown_device(ifi, kind, tb, ns, fds);
659683
}
660684

685+
static int dump_sit(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nlattr **info)
686+
{
687+
int ret;
688+
struct nlattr *data[__IFLA_IPTUN_MAX];
689+
SitEntry se = SIT_ENTRY__INIT;
690+
/* There are for IP(v6) addresses kernel feeds to us */
691+
uint32_t a_local, a_remote, rd_prefix[4], rl_prefix;
692+
693+
if (!info || !info[IFLA_INFO_DATA]) {
694+
pr_err("no data for sit\n");
695+
return -1;
696+
}
697+
698+
pr_info("Some data for SIT provided\n");
699+
ret = nla_parse_nested(data, IFLA_IPTUN_MAX, info[IFLA_INFO_DATA], NULL);
700+
if (ret < 0) {
701+
pr_err("failed ot parse sit data\n");
702+
return -1;
703+
}
704+
705+
#define ENCODE_ENTRY(__type, __ifla, __proto) do { \
706+
if (data[__ifla]) { \
707+
se.__proto = *(__type *)nla_data(data[__ifla]); \
708+
if (se.__proto) \
709+
se.has_##__proto = true; \
710+
} \
711+
} while (0)
712+
713+
if (data[IFLA_IPTUN_LOCAL]) {
714+
a_local = *(u32 *)nla_data(data[IFLA_IPTUN_LOCAL]);
715+
if (a_local != 0) {
716+
se.n_local = 1;
717+
se.local = &a_local;
718+
}
719+
}
720+
721+
if (data[IFLA_IPTUN_REMOTE]) {
722+
a_remote = *(u32 *)nla_data(data[IFLA_IPTUN_REMOTE]);
723+
if (a_remote != 0) {
724+
se.n_remote = 1;
725+
se.remote = &a_remote;
726+
}
727+
}
728+
729+
ENCODE_ENTRY(u32, IFLA_IPTUN_LINK, link);
730+
ENCODE_ENTRY(u8, IFLA_IPTUN_TTL, ttl);
731+
ENCODE_ENTRY(u8, IFLA_IPTUN_TOS, tos);
732+
ENCODE_ENTRY(u16, IFLA_IPTUN_FLAGS, flags);
733+
ENCODE_ENTRY(u8, IFLA_IPTUN_PROTO, proto);
734+
735+
if (data[IFLA_IPTUN_PMTUDISC]) {
736+
u8 v;
737+
738+
v = *(u8 *)nla_data(data[IFLA_IPTUN_PMTUDISC]);
739+
if (v)
740+
se.pmtudisc = se.has_pmtudisc = true;
741+
}
742+
743+
ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_TYPE, encap_type);
744+
ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_FLAGS, encap_flags);
745+
ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_SPORT, encap_sport);
746+
ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_DPORT, encap_dport);
747+
748+
if (data[IFLA_IPTUN_6RD_PREFIXLEN]) {
749+
se.rd_prefixlen = *(u16 *)nla_data(data[IFLA_IPTUN_6RD_PREFIXLEN]);
750+
if (!se.rd_prefixlen)
751+
goto skip;
752+
753+
if (!data[IFLA_IPTUN_6RD_PREFIX]) {
754+
pr_err("No 6rd prefix for sit device\n");
755+
return -1;
756+
}
757+
758+
se.has_rd_prefixlen = true;
759+
memcpy(&rd_prefix, nla_data(data[IFLA_IPTUN_6RD_PREFIX]), sizeof(rd_prefix));
760+
se.n_rd_prefix = 4;
761+
se.rd_prefix = rd_prefix;
762+
763+
se.relay_prefixlen = *(u16 *)nla_data(data[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]);
764+
if (!se.relay_prefixlen)
765+
goto skip;
766+
767+
if (!data[IFLA_IPTUN_6RD_RELAY_PREFIX]) {
768+
pr_err("No 6rd relay prefix for sit device\n");
769+
return -1;
770+
}
771+
772+
se.has_relay_prefixlen = true;
773+
memcpy(&rl_prefix, nla_data(data[IFLA_IPTUN_6RD_RELAY_PREFIX]), sizeof(rl_prefix));
774+
se.n_relay_prefix = 1;
775+
se.relay_prefix = &rl_prefix;
776+
skip:;
777+
}
778+
779+
#undef ENCODE_ENTRY
780+
781+
nde->sit = &se;
782+
return write_netdev_img(nde, imgset, info);
783+
}
784+
661785
static int dump_one_sit(struct ifinfomsg *ifi, char *kind,
662-
struct nlattr **tb, struct cr_imgset *fds)
786+
struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
663787
{
664788
char *name;
665789

@@ -679,8 +803,7 @@ static int dump_one_sit(struct ifinfomsg *ifi, char *kind,
679803
return 0;
680804
}
681805

682-
pr_warn("SIT device %s not supported natively\n", name);
683-
return dump_unknown_device(ifi, kind, tb, fds);
806+
return dump_one_netdev(ND_TYPE__SIT, ifi, tb, ns, fds, dump_sit);
684807
}
685808

686809
static int list_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
@@ -727,7 +850,7 @@ static int dump_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
727850
ret = dump_one_gre(ifi, kind, tb, ns, fds);
728851
break;
729852
case ARPHRD_SIT:
730-
ret = dump_one_sit(ifi, kind, tb, fds);
853+
ret = dump_one_sit(ifi, kind, tb, ns, fds);
731854
break;
732855
default:
733856
unk:

images/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ proto-obj-y += time.o
6161
proto-obj-y += sysctl.o
6262
proto-obj-y += autofs.o
6363
proto-obj-y += macvlan.o
64+
proto-obj-y += sit.o
6465
proto-obj-y += remote-image.o
6566

6667
CFLAGS += -iquote $(obj)/

images/netdev.proto

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "macvlan.proto";
44
import "opts.proto";
55
import "tun.proto";
66
import "sysctl.proto";
7+
import "sit.proto";
78

89
enum nd_type {
910
LOOPBACK = 1;
@@ -19,6 +20,7 @@ enum nd_type {
1920
VENET = 5; /* OpenVZ device */
2021
BRIDGE = 6;
2122
MACVLAN = 7;
23+
SIT = 8;
2224
}
2325

2426
message net_device_entry {
@@ -44,6 +46,7 @@ message net_device_entry {
4446
optional uint32 peer_nsid = 13;
4547

4648
optional uint32 master = 14;
49+
optional sit_entry sit = 15;
4750
}
4851

4952
message netns_id {

images/sit.proto

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
syntax = "proto2";
2+
3+
import "opts.proto";
4+
5+
message sit_entry {
6+
optional uint32 link = 1;
7+
repeated uint32 local = 2 [(criu).ipadd = true];
8+
repeated uint32 remote = 3 [(criu).ipadd = true];
9+
optional uint32 ttl = 4;
10+
optional uint32 tos = 5;
11+
optional bool pmtudisc = 6;
12+
optional uint32 proto = 7;
13+
optional uint32 flags = 8;
14+
optional uint32 encap_type = 9;
15+
optional uint32 encap_flags = 10;
16+
optional uint32 encap_sport = 11;
17+
optional uint32 encap_dport = 12;
18+
optional uint32 rd_prefixlen = 13;
19+
repeated uint32 rd_prefix = 14 [(criu).ipadd = true];
20+
optional uint32 relay_prefixlen = 15;
21+
repeated uint32 relay_prefix = 16 [(criu).ipadd = true];
22+
};

0 commit comments

Comments
 (0)