aboutsummaryrefslogtreecommitdiffstats
path: root/samples/bpf/bpf_load.c
diff options
context:
space:
mode:
Diffstat (limited to 'samples/bpf/bpf_load.c')
-rw-r--r--samples/bpf/bpf_load.c102
1 files changed, 0 insertions, 102 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index 242631aa4ea2..69806d74fa53 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -695,105 +695,3 @@ struct ksym *ksym_search(long key)
695 return &syms[0]; 695 return &syms[0];
696} 696}
697 697
698int set_link_xdp_fd(int ifindex, int fd, __u32 flags)
699{
700 struct sockaddr_nl sa;
701 int sock, seq = 0, len, ret = -1;
702 char buf[4096];
703 struct nlattr *nla, *nla_xdp;
704 struct {
705 struct nlmsghdr nh;
706 struct ifinfomsg ifinfo;
707 char attrbuf[64];
708 } req;
709 struct nlmsghdr *nh;
710 struct nlmsgerr *err;
711
712 memset(&sa, 0, sizeof(sa));
713 sa.nl_family = AF_NETLINK;
714
715 sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
716 if (sock < 0) {
717 printf("open netlink socket: %s\n", strerror(errno));
718 return -1;
719 }
720
721 if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
722 printf("bind to netlink: %s\n", strerror(errno));
723 goto cleanup;
724 }
725
726 memset(&req, 0, sizeof(req));
727 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
728 req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
729 req.nh.nlmsg_type = RTM_SETLINK;
730 req.nh.nlmsg_pid = 0;
731 req.nh.nlmsg_seq = ++seq;
732 req.ifinfo.ifi_family = AF_UNSPEC;
733 req.ifinfo.ifi_index = ifindex;
734
735 /* started nested attribute for XDP */
736 nla = (struct nlattr *)(((char *)&req)
737 + NLMSG_ALIGN(req.nh.nlmsg_len));
738 nla->nla_type = NLA_F_NESTED | 43/*IFLA_XDP*/;
739 nla->nla_len = NLA_HDRLEN;
740
741 /* add XDP fd */
742 nla_xdp = (struct nlattr *)((char *)nla + nla->nla_len);
743 nla_xdp->nla_type = 1/*IFLA_XDP_FD*/;
744 nla_xdp->nla_len = NLA_HDRLEN + sizeof(int);
745 memcpy((char *)nla_xdp + NLA_HDRLEN, &fd, sizeof(fd));
746 nla->nla_len += nla_xdp->nla_len;
747
748 /* if user passed in any flags, add those too */
749 if (flags) {
750 nla_xdp = (struct nlattr *)((char *)nla + nla->nla_len);
751 nla_xdp->nla_type = 3/*IFLA_XDP_FLAGS*/;
752 nla_xdp->nla_len = NLA_HDRLEN + sizeof(flags);
753 memcpy((char *)nla_xdp + NLA_HDRLEN, &flags, sizeof(flags));
754 nla->nla_len += nla_xdp->nla_len;
755 }
756
757 req.nh.nlmsg_len += NLA_ALIGN(nla->nla_len);
758
759 if (send(sock, &req, req.nh.nlmsg_len, 0) < 0) {
760 printf("send to netlink: %s\n", strerror(errno));
761 goto cleanup;
762 }
763
764 len = recv(sock, buf, sizeof(buf), 0);
765 if (len < 0) {
766 printf("recv from netlink: %s\n", strerror(errno));
767 goto cleanup;
768 }
769
770 for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len);
771 nh = NLMSG_NEXT(nh, len)) {
772 if (nh->nlmsg_pid != getpid()) {
773 printf("Wrong pid %d, expected %d\n",
774 nh->nlmsg_pid, getpid());
775 goto cleanup;
776 }
777 if (nh->nlmsg_seq != seq) {
778 printf("Wrong seq %d, expected %d\n",
779 nh->nlmsg_seq, seq);
780 goto cleanup;
781 }
782 switch (nh->nlmsg_type) {
783 case NLMSG_ERROR:
784 err = (struct nlmsgerr *)NLMSG_DATA(nh);
785 if (!err->error)
786 continue;
787 printf("nlmsg error %s\n", strerror(-err->error));
788 goto cleanup;
789 case NLMSG_DONE:
790 break;
791 }
792 }
793
794 ret = 0;
795
796cleanup:
797 close(sock);
798 return ret;
799}