MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rtsock_addrmsg

Function rtsock_addrmsg

freebsd/net/rtsock.c:1837–1875  ·  view source on GitHub ↗

* Announce interface address arrival/withdraw. * Please do not call directly, use rt_addrmsg(). * Assume input data to be valid. * Returns 0 on success. */

Source from the content-addressed store, hash-verified

1835 * Returns 0 on success.
1836 */
1837int
1838rtsock_addrmsg(int cmd, struct ifaddr *ifa, int fibnum)
1839{
1840 struct rt_addrinfo info;
1841 struct sockaddr *sa;
1842 int ncmd;
1843 struct mbuf *m;
1844 struct ifa_msghdr *ifam;
1845 struct ifnet *ifp = ifa->ifa_ifp;
1846 struct sockaddr_storage ss;
1847
1848 if (V_route_cb.any_count == 0)
1849 return (0);
1850
1851 ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR;
1852
1853 bzero((caddr_t)&info, sizeof(info));
1854 info.rti_info[RTAX_IFA] = sa = ifa->ifa_addr;
1855 info.rti_info[RTAX_IFP] = ifp->if_addr->ifa_addr;
1856 info.rti_info[RTAX_NETMASK] = rtsock_fix_netmask(
1857 info.rti_info[RTAX_IFA], ifa->ifa_netmask, &ss);
1858 info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
1859 if ((m = rtsock_msg_mbuf(ncmd, &info)) == NULL)
1860 return (ENOBUFS);
1861 ifam = mtod(m, struct ifa_msghdr *);
1862 ifam->ifam_index = ifp->if_index;
1863 ifam->ifam_metric = ifa->ifa_ifp->if_metric;
1864 ifam->ifam_flags = ifa->ifa_flags;
1865 ifam->ifam_addrs = info.rti_addrs;
1866
1867 if (fibnum != RT_ALL_FIBS) {
1868 M_SETFIB(m, fibnum);
1869 m->m_flags |= RTS_FILTER_FIB;
1870 }
1871
1872 rt_dispatch(m, sa ? sa->sa_family : AF_UNSPEC);
1873
1874 return (0);
1875}
1876
1877/*
1878 * Announce route addition/removal to rtsock based on @rt data.

Callers 1

rt_addrmsgFunction · 0.85

Calls 4

bzeroFunction · 0.85
rtsock_msg_mbufFunction · 0.85
rt_dispatchFunction · 0.85
rtsock_fix_netmaskFunction · 0.70

Tested by

no test coverage detected