l2tp: style cleanup

Make l2tp conform to kernel style guidelines
This commit is contained in:
Stephen Hemminger 2016-11-29 13:40:06 -08:00
parent 51a9d01aaa
commit 281db53ff8

View File

@ -110,11 +110,13 @@ static int create_tunnel(struct l2tp_parm *p)
if (p->local_ip.family == AF_INET6)
local_attr = L2TP_ATTR_IP6_SADDR;
addattr_l(&req.n, 1024, local_attr, &p->local_ip.data, p->local_ip.bytelen);
addattr_l(&req.n, 1024, local_attr, &p->local_ip.data,
p->local_ip.bytelen);
if (p->peer_ip.family == AF_INET6)
peer_attr = L2TP_ATTR_IP6_DADDR;
addattr_l(&req.n, 1024, peer_attr, &p->peer_ip.data, p->peer_ip.bytelen);
addattr_l(&req.n, 1024, peer_attr, &p->peer_ip.data,
p->peer_ip.bytelen);
if (p->encap == L2TP_ENCAPTYPE_UDP) {
addattr16(&req.n, 1024, L2TP_ATTR_UDP_SPORT, p->local_udp_port);
@ -159,18 +161,27 @@ static int create_session(struct l2tp_parm *p)
addattr8(&req.n, 1024, L2TP_ATTR_L2SPEC_TYPE, p->l2spec_type);
addattr8(&req.n, 1024, L2TP_ATTR_L2SPEC_LEN, p->l2spec_len);
if (p->mtu) addattr16(&req.n, 1024, L2TP_ATTR_MTU, p->mtu);
if (p->recv_seq) addattr8(&req.n, 1024, L2TP_ATTR_RECV_SEQ, 1);
if (p->send_seq) addattr8(&req.n, 1024, L2TP_ATTR_SEND_SEQ, 1);
if (p->lns_mode) addattr(&req.n, 1024, L2TP_ATTR_LNS_MODE);
if (p->data_seq) addattr8(&req.n, 1024, L2TP_ATTR_DATA_SEQ, p->data_seq);
if (p->reorder_timeout) addattr64(&req.n, 1024, L2TP_ATTR_RECV_TIMEOUT,
if (p->mtu)
addattr16(&req.n, 1024, L2TP_ATTR_MTU, p->mtu);
if (p->recv_seq)
addattr8(&req.n, 1024, L2TP_ATTR_RECV_SEQ, 1);
if (p->send_seq)
addattr8(&req.n, 1024, L2TP_ATTR_SEND_SEQ, 1);
if (p->lns_mode)
addattr(&req.n, 1024, L2TP_ATTR_LNS_MODE);
if (p->data_seq)
addattr8(&req.n, 1024, L2TP_ATTR_DATA_SEQ, p->data_seq);
if (p->reorder_timeout)
addattr64(&req.n, 1024, L2TP_ATTR_RECV_TIMEOUT,
p->reorder_timeout);
if (p->offset) addattr16(&req.n, 1024, L2TP_ATTR_OFFSET, p->offset);
if (p->cookie_len) addattr_l(&req.n, 1024, L2TP_ATTR_COOKIE,
p->cookie, p->cookie_len);
if (p->peer_cookie_len) addattr_l(&req.n, 1024, L2TP_ATTR_PEER_COOKIE,
p->peer_cookie, p->peer_cookie_len);
if (p->offset)
addattr16(&req.n, 1024, L2TP_ATTR_OFFSET, p->offset);
if (p->cookie_len)
addattr_l(&req.n, 1024, L2TP_ATTR_COOKIE,
p->cookie, p->cookie_len);
if (p->peer_cookie_len)
addattr_l(&req.n, 1024, L2TP_ATTR_PEER_COOKIE,
p->peer_cookie, p->peer_cookie_len);
if (p->ifname && p->ifname[0])
addattrstrz(&req.n, 1024, L2TP_ATTR_IFNAME, p->ifname);
@ -213,8 +224,12 @@ static void print_tunnel(const struct l2tp_data *data)
p->tunnel_id,
p->encap == L2TP_ENCAPTYPE_UDP ? "UDP" :
p->encap == L2TP_ENCAPTYPE_IP ? "IP" : "??");
printf(" From %s ", inet_ntop(p->local_ip.family, p->local_ip.data, buf, sizeof(buf)));
printf("to %s\n", inet_ntop(p->peer_ip.family, p->peer_ip.data, buf, sizeof(buf)));
printf(" From %s ",
inet_ntop(p->local_ip.family, p->local_ip.data,
buf, sizeof(buf)));
printf("to %s\n",
inet_ntop(p->peer_ip.family, p->peer_ip.data,
buf, sizeof(buf)));
printf(" Peer tunnel %u\n",
p->peer_tunnel_id);
@ -229,10 +244,14 @@ static void print_tunnel(const struct l2tp_data *data)
break;
case AF_INET6:
printf(" UDP checksum: %s%s%s%s\n",
p->udp6_csum_tx && p->udp6_csum_rx ? "enabled" : "",
p->udp6_csum_tx && !p->udp6_csum_rx ? "tx" : "",
!p->udp6_csum_tx && p->udp6_csum_rx ? "rx" : "",
!p->udp6_csum_tx && !p->udp6_csum_rx ? "disabled" : "");
p->udp6_csum_tx && p->udp6_csum_rx
? "enabled" : "",
p->udp6_csum_tx && !p->udp6_csum_rx
? "tx" : "",
!p->udp6_csum_tx && p->udp6_csum_rx
? "rx" : "",
!p->udp6_csum_tx && !p->udp6_csum_rx
? "disabled" : "");
break;
}
}
@ -247,9 +266,9 @@ static void print_session(struct l2tp_data *data)
printf(" Peer session %u, tunnel %u\n",
p->peer_session_id, p->peer_tunnel_id);
if (p->ifname != NULL) {
if (p->ifname != NULL)
printf(" interface name: %s\n", p->ifname);
}
printf(" offset %u, peer offset %u\n",
p->offset, p->peer_offset);
if (p->cookie_len > 0)
@ -263,8 +282,10 @@ static void print_session(struct l2tp_data *data)
printf("\n");
if (p->send_seq || p->recv_seq) {
printf(" sequence numbering:");
if (p->send_seq) printf(" send");
if (p->recv_seq) printf(" recv");
if (p->send_seq)
printf(" send");
if (p->recv_seq)
printf(" recv");
printf("\n");
}
}
@ -391,7 +412,8 @@ static int get_response(struct nlmsghdr *n, void *arg)
return 0;
}
static int session_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
static int session_nlmsg(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg)
{
int ret = get_response(n, arg);
@ -411,7 +433,8 @@ static int get_session(struct l2tp_data *p)
if (p->config.tunnel_id && p->config.session_id) {
addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->config.tunnel_id);
addattr32(&req.n, 128, L2TP_ATTR_SESSION_ID, p->config.session_id);
addattr32(&req.n, 128, L2TP_ATTR_SESSION_ID,
p->config.session_id);
}
if (rtnl_send(&genl_rth, &req, req.n.nlmsg_len) < 0)
@ -425,7 +448,8 @@ static int get_session(struct l2tp_data *p)
return 0;
}
static int tunnel_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
static int tunnel_nlmsg(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg)
{
int ret = get_response(n, arg);
@ -490,32 +514,33 @@ static void usage(void) __attribute__((noreturn));
static void usage(void)
{
fprintf(stderr, "Usage: ip l2tp add tunnel\n");
fprintf(stderr, " remote ADDR local ADDR\n");
fprintf(stderr, " tunnel_id ID peer_tunnel_id ID\n");
fprintf(stderr, " [ encap { ip | udp } ]\n");
fprintf(stderr, " [ udp_sport PORT ] [ udp_dport PORT ]\n");
fprintf(stderr, " [ udp_csum { on | off } ]\n");
fprintf(stderr, " [ udp6_csum_tx { on | off } ]\n");
fprintf(stderr, " [ udp6_csum_rx { on | off } ]\n");
fprintf(stderr, "Usage: ip l2tp add session [ name NAME ]\n");
fprintf(stderr, " tunnel_id ID\n");
fprintf(stderr, " session_id ID peer_session_id ID\n");
fprintf(stderr, " [ cookie HEXSTR ] [ peer_cookie HEXSTR ]\n");
fprintf(stderr, " [ offset OFFSET ] [ peer_offset OFFSET ]\n");
fprintf(stderr, " [ seq { none | send | recv | both } ]\n");
fprintf(stderr, " [ l2spec_type L2SPEC ]\n");
fprintf(stderr, " ip l2tp del tunnel tunnel_id ID\n");
fprintf(stderr, " ip l2tp del session tunnel_id ID session_id ID\n");
fprintf(stderr, " ip l2tp show tunnel [ tunnel_id ID ]\n");
fprintf(stderr, " ip l2tp show session [ tunnel_id ID ] [ session_id ID ]\n");
fprintf(stderr, "\n");
fprintf(stderr, "Where: NAME := STRING\n");
fprintf(stderr, " ADDR := { IP_ADDRESS | any }\n");
fprintf(stderr, " PORT := { 0..65535 }\n");
fprintf(stderr, " ID := { 1..4294967295 }\n");
fprintf(stderr, " HEXSTR := { 8 or 16 hex digits (4 / 8 bytes) }\n");
fprintf(stderr, " L2SPEC := { none | default }\n");
fprintf(stderr, "Usage: ip l2tp add tunnel\n"
" remote ADDR local ADDR\n"
" tunnel_id ID peer_tunnel_id ID\n"
" [ encap { ip | udp } ]\n"
" [ udp_sport PORT ] [ udp_dport PORT ]\n"
" [ udp_csum { on | off } ]\n"
" [ udp6_csum_tx { on | off } ]\n"
" [ udp6_csum_rx { on | off } ]\n"
"Usage: ip l2tp add session [ name NAME ]\n"
" tunnel_id ID\n"
" session_id ID peer_session_id ID\n"
" [ cookie HEXSTR ] [ peer_cookie HEXSTR ]\n"
" [ offset OFFSET ] [ peer_offset OFFSET ]\n"
" [ seq { none | send | recv | both } ]\n"
" [ l2spec_type L2SPEC ]\n"
" ip l2tp del tunnel tunnel_id ID\n"
" ip l2tp del session tunnel_id ID session_id ID\n"
" ip l2tp show tunnel [ tunnel_id ID ]\n"
" ip l2tp show session [ tunnel_id ID ] [ session_id ID ]\n"
"\n"
"Where: NAME := STRING\n"
" ADDR := { IP_ADDRESS | any }\n"
" PORT := { 0..65535 }\n"
" ID := { 1..4294967295 }\n"
" HEXSTR := { 8 or 16 hex digits (4 / 8 bytes) }\n"
" L2SPEC := { none | default }\n");
exit(-1);
}
@ -671,7 +696,9 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
p->l2spec_type = L2TP_L2SPECTYPE_NONE;
p->l2spec_len = 0;
} else {
fprintf(stderr, "Unknown layer2specific header type \"%s\"\n", *argv);
fprintf(stderr,
"Unknown layer2specific header type \"%s\"\n",
*argv);
exit(-1);
}
} else if (strcmp(*argv, "seq") == 0) {
@ -687,7 +714,8 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
p->recv_seq = 0;
p->send_seq = 0;
} else {
fprintf(stderr, "Unknown seq value \"%s\"\n", *argv);
fprintf(stderr,
"Unknown seq value \"%s\"\n", *argv);
exit(-1);
}
} else if (strcmp(*argv, "tunnel") == 0) {
@ -818,6 +846,7 @@ int do_ipl2tp(int argc, char **argv)
matches(*argv, "list") == 0)
return do_show(argc-1, argv+1);
fprintf(stderr, "Command \"%s\" is unknown, try \"ip l2tp help\".\n", *argv);
fprintf(stderr,
"Command \"%s\" is unknown, try \"ip l2tp help\".\n", *argv);
exit(-1);
}