+
+int
+udp_lock(so, refcount, debug)
+ struct socket *so;
+ int refcount, debug;
+{
+ int lr_saved;
+#ifdef __ppc__
+ if (debug == 0) {
+ __asm__ volatile("mflr %0" : "=r" (lr_saved));
+ }
+ else lr_saved = debug;
+#endif
+
+ if (so->so_pcb) {
+ lck_mtx_assert(((struct inpcb *)so->so_pcb)->inpcb_mtx, LCK_MTX_ASSERT_NOTOWNED);
+ lck_mtx_lock(((struct inpcb *)so->so_pcb)->inpcb_mtx);
+ }
+ else {
+ panic("udp_lock: so=%x NO PCB! lr=%x\n", so, lr_saved);
+ lck_mtx_assert(so->so_proto->pr_domain->dom_mtx, LCK_MTX_ASSERT_NOTOWNED);
+ lck_mtx_lock(so->so_proto->pr_domain->dom_mtx);
+ }
+
+ if (refcount)
+ so->so_usecount++;
+
+ so->reserved3= lr_saved;
+ return (0);
+}
+
+int
+udp_unlock(so, refcount, debug)
+ struct socket *so;
+ int refcount;
+ int debug;
+{
+ int lr_saved;
+ struct inpcb *inp = sotoinpcb(so);
+ struct inpcbinfo *pcbinfo = &udbinfo;
+#ifdef __ppc__
+ if (debug == 0) {
+ __asm__ volatile("mflr %0" : "=r" (lr_saved));
+ }
+ else lr_saved = debug;
+#endif
+ if (refcount) {
+ so->so_usecount--;
+#if 0
+ if (so->so_usecount == 0 && (inp->inp_wantcnt == WNT_STOPUSING)) {
+ if (lck_rw_try_lock_exclusive(pcbinfo->mtx)) {
+ in_pcbdispose(inp);
+ lck_rw_done(pcbinfo->mtx);
+ return(0);
+ }
+ }
+#endif
+ }
+ if (so->so_pcb == NULL) {
+ panic("udp_unlock: so=%x NO PCB! lr=%x\n", so, lr_saved);
+ lck_mtx_assert(so->so_proto->pr_domain->dom_mtx, LCK_MTX_ASSERT_OWNED);
+ lck_mtx_unlock(so->so_proto->pr_domain->dom_mtx);
+ }
+ else {
+ lck_mtx_assert(((struct inpcb *)so->so_pcb)->inpcb_mtx, LCK_MTX_ASSERT_OWNED);
+ lck_mtx_unlock(((struct inpcb *)so->so_pcb)->inpcb_mtx);
+ }
+
+
+ so->reserved4 = lr_saved;
+ return (0);
+}
+
+lck_mtx_t *
+udp_getlock(so, locktype)
+ struct socket *so;
+ int locktype;
+{
+ struct inpcb *inp = sotoinpcb(so);
+
+
+ if (so->so_pcb)
+ return(inp->inpcb_mtx);
+ else {
+ panic("udp_getlock: so=%x NULL so_pcb\n", so);
+ return (so->so_proto->pr_domain->dom_mtx);
+ }
+}
+
+void
+udp_slowtimo()
+{
+ struct inpcb *inp, *inpnxt;
+ struct socket *so;
+ struct inpcbinfo *pcbinfo = &udbinfo;
+
+ lck_rw_lock_exclusive(pcbinfo->mtx);
+
+ for (inp = udb.lh_first; inp != NULL; inp = inpnxt) {
+ inpnxt = inp->inp_list.le_next;
+
+ /* Ignore nat/SharedIP dummy pcbs */
+ if (inp->inp_socket == &udbinfo.nat_dummy_socket)
+ continue;
+
+ if (inp->inp_wantcnt != WNT_STOPUSING)
+ continue;
+
+ so = inp->inp_socket;
+ if (!lck_mtx_try_lock(inp->inpcb_mtx)) /* skip if busy, no hurry for cleanup... */
+ continue;
+
+ if (so->so_usecount == 0)
+ in_pcbdispose(inp);
+ else
+ lck_mtx_unlock(inp->inpcb_mtx);
+ }
+ lck_rw_done(pcbinfo->mtx);
+}
+
+int
+ChkAddressOK( __uint32_t dstaddr, __uint32_t srcaddr )
+{
+ if ( dstaddr == srcaddr ){
+ return 0;
+ }
+ return 1;
+}
+