@@ -1063,6 +1063,77 @@ static int linkmap_add_entry(mctp_nl *nl, struct ifinfomsg *info,
10631063 return 0 ;
10641064}
10651065
1066+ /* Common parts of RTM_NEWADDR and RTM_DELADDR */
1067+ struct mctp_ifaddralter_msg {
1068+ struct nlmsghdr nh ;
1069+ struct ifaddrmsg ifmsg ;
1070+ struct rtattr rta ;
1071+ uint8_t data [4 ];
1072+ };
1073+
1074+ static int fill_ifaddralter_args (struct mctp_nl * nl ,
1075+ struct mctp_ifaddralter_msg * msg ,
1076+ struct rtattr * * prta , size_t * prta_len ,
1077+ mctp_eid_t eid , const char * linkstr )
1078+ {
1079+ int ifindex ;
1080+
1081+ ifindex = mctp_nl_ifindex_byname (nl , linkstr );
1082+ if (!ifindex ) {
1083+ warnx ("invalid device %s" , linkstr );
1084+ return -1 ;
1085+ }
1086+
1087+ memset (msg , 0x0 , sizeof (* msg ));
1088+
1089+ msg -> nh .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK ;
1090+
1091+ msg -> ifmsg .ifa_index = ifindex ;
1092+ msg -> ifmsg .ifa_family = AF_MCTP ;
1093+
1094+ msg -> rta .rta_type = IFA_LOCAL ;
1095+ msg -> rta .rta_len = RTA_LENGTH (sizeof (eid ));
1096+ memcpy (RTA_DATA (& msg -> rta ), & eid , sizeof (eid ));
1097+
1098+ msg -> nh .nlmsg_len =
1099+ NLMSG_LENGTH (sizeof (msg -> ifmsg )) + RTA_SPACE (sizeof (eid ));
1100+
1101+ if (prta )
1102+ * prta = & msg -> rta ;
1103+ if (prta_len )
1104+ * prta_len = msg -> rta .rta_len ;
1105+
1106+ return 0 ;
1107+ }
1108+
1109+ int mctp_nl_addr_add (struct mctp_nl * nl , mctp_eid_t eid , const char * linkstr )
1110+ {
1111+ struct mctp_ifaddralter_msg msg ;
1112+ int rc ;
1113+
1114+ rc = fill_ifaddralter_args (nl , & msg , NULL , NULL , eid , linkstr );
1115+ if (rc )
1116+ return -1 ;
1117+
1118+ msg .nh .nlmsg_type = RTM_NEWADDR ;
1119+
1120+ return mctp_nl_send (nl , & msg .nh );
1121+ }
1122+
1123+ int mctp_nl_addr_del (struct mctp_nl * nl , mctp_eid_t eid , const char * linkstr )
1124+ {
1125+ struct mctp_ifaddralter_msg msg ;
1126+ int rc ;
1127+
1128+ rc = fill_ifaddralter_args (nl , & msg , NULL , NULL , eid , linkstr );
1129+ if (rc )
1130+ return -1 ;
1131+
1132+ msg .nh .nlmsg_type = RTM_DELADDR ;
1133+
1134+ return mctp_nl_send (nl , & msg .nh );
1135+ }
1136+
10661137/* Common parts of RTM_NEWROUTE and RTM_DELROUTE */
10671138struct mctp_rtalter_msg {
10681139 struct nlmsghdr nh ;
0 commit comments